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.
54 55 56 57 58 59 60 |
# File 'lib/td/command/list.rb', line 54 def initialize(name, args, description, examples) @name = name @args = args @description = description.to_s @examples = examples @override_message = nil end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
62 63 64 |
# File 'lib/td/command/list.rb', line 62 def args @args end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
62 63 64 |
# File 'lib/td/command/list.rb', line 62 def description @description end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
62 63 64 |
# File 'lib/td/command/list.rb', line 62 def examples @examples end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
62 63 64 |
# File 'lib/td/command/list.rb', line 62 def name @name end |
#override_message ⇒ Object
Returns the value of attribute override_message.
63 64 65 |
# File 'lib/td/command/list.rb', line 63 def @override_message end |
Instance Method Details
#compile! ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/td/command/list.rb', line 65 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
85 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 |
# File 'lib/td/command/list.rb', line 85 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 = @override_message (class << op;self;end).module_eval do define_method(:to_s) { msg } end end op end |
#group ⇒ Object
121 122 123 |
# File 'lib/td/command/list.rb', line 121 def group @name.split(':', 2).first end |
#usage ⇒ Object
116 117 118 119 |
# File 'lib/td/command/list.rb', line 116 def usage compile! "%-40s # %s" % [@usage_args, @description] end |