Class: SpecificHelp::Command
- Inherits:
-
Object
- Object
- SpecificHelp::Command
- Defined in:
- lib/specific_help.rb
Class Method Summary collapse
Instance Method Summary collapse
- #disp(lines) ⇒ Object
- #disp_from_help_cont(key_word) ⇒ Object
- #execute ⇒ Object
-
#initialize(file, argv = []) ⇒ Command
constructor
A new instance of Command.
- #to_hiki ⇒ Object
Constructor Details
#initialize(file, argv = []) ⇒ Command
Returns a new instance of Command.
14 15 16 17 18 |
# File 'lib/specific_help.rb', line 14 def initialize(file,argv=[]) @help_cont = YAML.load(File.read(file)) @help_cont[:head].each{|line| print line } @argv = argv end |
Class Method Details
.run(file, argv = []) ⇒ Object
10 11 12 |
# File 'lib/specific_help.rb', line 10 def self.run(file,argv=[]) new(file, argv).execute end |
Instance Method Details
#disp(lines) ⇒ Object
54 55 56 57 58 |
# File 'lib/specific_help.rb', line 54 def disp(lines) lines.each{|line| puts " #{line}" } end |
#disp_from_help_cont(key_word) ⇒ Object
60 61 62 63 64 |
# File 'lib/specific_help.rb', line 60 def disp_from_help_cont(key_word) items =@help_cont[key_word] puts items[:title] disp(items[:cont]) end |
#execute ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/specific_help.rb', line 20 def execute @argv << '--help' if @argv.size==0 command_parser = OptionParser.new do |opt| opt.on('-v', '--version','show program Version.') { |v| opt.version = MyHelp::VERSION puts opt.ver } @help_cont.each_pair{|key,val| next if key==:head opts = val[:opts] opt.on(opts[:short],opts[:long],opts[:desc]) {disp_from_help_cont(key)} } opt.on('--to_hiki','convert to hikidoc format'){to_hiki} end # begin command_parser.parse!(@argv) # rescue=> eval # p eval # end exit end |
#to_hiki ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/specific_help.rb', line 42 def to_hiki puts '>>>' @help_cont.each_pair{|key,val| p key,val # opts = val[:opts] # puts opts[:short].to_s,opts[:long].to_s,opts[:desc].to_s items =@help_cont[key] puts items[:title] disp(items[:cont]) } end |