Class: EmacsHelp::Command
- Inherits:
-
Object
- Object
- EmacsHelp::Command
- Defined in:
- lib/emacs_help.rb
Class Method Summary collapse
Instance Method Summary collapse
- #disp(lines) ⇒ Object
- #disp_from_help_cont(key_word) ⇒ Object
- #execute ⇒ Object
-
#initialize(argv = []) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(argv = []) ⇒ Command
Returns a new instance of Command.
13 14 15 16 17 |
# File 'lib/emacs_help.rb', line 13 def initialize(argv=[]) @help_cont = YAML.load(File.read('lib/daddygongon/emacs_help')) @help_cont[:head].each{|line| print line } @argv = argv end |
Class Method Details
.run(argv = []) ⇒ Object
9 10 11 |
# File 'lib/emacs_help.rb', line 9 def self.run(argv=[]) new(argv).execute end |
Instance Method Details
#disp(lines) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/emacs_help.rb', line 40 def disp(lines) lines.each{|line| if line.include?(',') puts " #{line}" else puts " #{line}" end } end |
#disp_from_help_cont(key_word) ⇒ Object
50 51 52 53 54 |
# File 'lib/emacs_help.rb', line 50 def disp_from_help_cont(key_word) items =@help_cont[key_word] puts items[:title] disp(items[:cont]) end |
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/emacs_help.rb', line 19 def execute @argv << '--help' if @argv.size==0 command_parser = OptionParser.new do |opt| opt.on('-v', '--version','show program Version.') { |v| opt.version = EmacsHelp::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 |