Method: Command::CommandBase#initialize
- Defined in:
- lib/commandbase.rb
#initialize(postfixies = "") ⇒ CommandBase
postfixies は改行で区切ることで2パターン以上記述できる
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/commandbase.rb', line 12 def initialize(postfixies = "") @opt = OptionParser.new(nil, 20) command_name = self.class.to_s.scan(/::(.+)$/)[0][0].downcase = postfixies.split("\n").map.with_index { |postfix, i| (i == 0 ? "Usage: " : " or: ") + "narou #{command_name} #{postfix}" }.join("\n") @opt. = "<bold><green>#{TermColorLight.escape(banner)}</green></bold>".termcolor = {} # ヘルプを見やすく色付け def @opt.help msg = super # 見出し部分 msg.gsub!(/((?:Examples|Options|Configuration|[^\s]+? Variable List):)/) do "<underline><bold>#{$1}</bold></underline>".termcolor end # Examples のコメント部分 msg.gsub!(/(#.+)$/) do "<cyan>#{TermColorLight.escape($1)}</cyan>".termcolor end # 文字列部分 msg.gsub!(/(".+?")/) do "<yellow>#{TermColorLight.escape($1)}</yellow>".termcolor end msg end end |