Sha256: fa3e4907f026776a0796af9ece20f10021087e8a510400f14bf549e9a40e5bd4
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 KB
Contents
# -*- coding: utf-8 -*- require "optparse" require "yaml" require "my_help/version" module SpecificHelp class Command def self.run(file,argv=[]) new(file, argv).execute end def initialize(file,argv=[]) @help_cont = YAML.load(File.read(file)) @help_cont[:head].each{|line| print line } @argv = argv end 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 def disp(lines) lines.each{|line| if line.include?(',') puts " #{line}" else puts " #{line}" end } end def disp_from_help_cont(key_word) items =@help_cont[key_word] puts items[:title] disp(items[:cont]) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
my_help-0.2.3 | lib/specific_help.rb |
my_help-0.2.2 | lib/specific_help.rb |
my_help-0.2.1 | lib/specific_help.rb |