Class: TreasureData::Command::List::CommandOption
- Inherits:
-
Object
- Object
- TreasureData::Command::List::CommandOption
- Defined in:
- lib/td/command/list.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#override_message ⇒ Object
Returns the value of attribute override_message.
Instance Method Summary collapse
- #compile! ⇒ Object
- #create_optparse(argv) ⇒ Object
- #group ⇒ Object
-
#initialize(name, args, description, examples) ⇒ CommandOption
constructor
A new instance of CommandOption.
- #usage ⇒ Object
Constructor Details
#initialize(name, args, description, examples) ⇒ CommandOption
Returns a new instance of CommandOption.
55 56 57 58 59 60 61 |
# File 'lib/td/command/list.rb', line 55 def initialize(name, args, description, examples) @name = name @args = args @description = description.to_s @examples = examples = nil end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
63 64 65 |
# File 'lib/td/command/list.rb', line 63 def args @args end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
63 64 65 |
# File 'lib/td/command/list.rb', line 63 def description @description end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
63 64 65 |
# File 'lib/td/command/list.rb', line 63 def examples @examples end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
63 64 65 |
# File 'lib/td/command/list.rb', line 63 def name @name end |
#override_message ⇒ Object
Returns the value of attribute override_message.
64 65 66 |
# File 'lib/td/command/list.rb', line 64 def end |
Instance Method Details
#compile! ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/td/command/list.rb', line 66 def compile! return if @usage_args args = @args.dup if args.last.to_s =~ /_$/ @varlen = true args.push args.pop.to_s[0..-2]+'...' elsif args.last.to_s =~ /_\?$/ @varlen = true args.push args.pop.to_s[0..-3]+'...?' end @req_args, @opt_args = args.partition {|a| a.to_s !~ /\?$/ } @opt_args = @opt_args.map {|a| a.to_s[0..-2].to_sym } @usage_args = "#{@name}" @req_args.each {|a| @usage_args << " <#{a}>" } @opt_args.each {|a| @usage_args << " [#{a}]" } end |
#create_optparse(argv) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/td/command/list.rb', line 86 def create_optparse(argv) compile! op = CommandParser.new(@name, @req_args, @opt_args, @varlen, argv) = "usage:\n" << " $ #{File.basename($0)} #{@usage_args}\n" unless @examples.empty? << "\n" << "example:\n" @examples.each {|l| << " $ #{File.basename($0)} #{l}\n" } end << "\n" << "description:\n" @description.split("\n").each {|l| << " #{l}\n" } op. = op.summary_indent = " " if msg = (class << op;self;end).module_eval do define_method(:to_s) { msg } end end op end |
#group ⇒ Object
122 123 124 |
# File 'lib/td/command/list.rb', line 122 def group @name.split(':', 2).first end |
#usage ⇒ Object
117 118 119 120 |
# File 'lib/td/command/list.rb', line 117 def usage compile! "%-40s # %s" % [@usage_args, @description] end |