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.
Constructor Details
#initialize(file, argv = []) ⇒ 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
41 42 43 44 45 46 47 48 49 |
# File 'lib/specific_help.rb', line 41 def disp(lines) lines.each{|line| if line.include?(',') puts " #{line}" else puts " #{line}" end } end |
#disp_from_help_cont(key_word) ⇒ Object
51 52 53 54 55 |
# File 'lib/specific_help.rb', line 51 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 |
# 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)} } end begin command_parser.parse!(@argv) rescue=> eval p eval end exit end |