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.
-
#req_conn ⇒ Object
readonly
Returns the value of attribute req_conn.
Instance Method Summary collapse
- #compile! ⇒ Object
- #create_optparse(argv) ⇒ Object
- #group ⇒ Object
-
#initialize(name, args, description, examples = [], req_conn = true) ⇒ CommandOption
constructor
A new instance of CommandOption.
- #usage ⇒ Object
Constructor Details
#initialize(name, args, description, examples = [], req_conn = true) ⇒ CommandOption
Returns a new instance of CommandOption.
56 57 58 59 60 61 62 63 |
# File 'lib/td/command/list.rb', line 56 def initialize(name, args, description, examples = [], req_conn = true) @name = name @args = args @description = description.to_s @examples = examples @req_conn = req_conn @override_message = nil end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
65 66 67 |
# File 'lib/td/command/list.rb', line 65 def args @args end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
65 66 67 |
# File 'lib/td/command/list.rb', line 65 def description @description end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
65 66 67 |
# File 'lib/td/command/list.rb', line 65 def examples @examples end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
65 66 67 |
# File 'lib/td/command/list.rb', line 65 def name @name end |
#override_message ⇒ Object
Returns the value of attribute override_message.
66 67 68 |
# File 'lib/td/command/list.rb', line 66 def @override_message end |
#req_conn ⇒ Object (readonly)
Returns the value of attribute req_conn.
65 66 67 |
# File 'lib/td/command/list.rb', line 65 def req_conn @req_conn end |
Instance Method Details
#compile! ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/td/command/list.rb', line 68 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
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 116 117 |
# File 'lib/td/command/list.rb', line 88 def create_optparse(argv) compile! op = CommandParser.new(@name, @req_args, @opt_args, @varlen, argv, @req_conn) = "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
132 133 134 |
# File 'lib/td/command/list.rb', line 132 def group @name.split(':', 2).first end |
#usage ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/td/command/list.rb', line 119 def usage compile! description_lines = @description.split("\n") strout = "%-40s # %s" % [@usage_args, description_lines[0]] if description_lines.length > 1 description_lines[1..-1].each {|lines| strout += "\n" strout += "%-40s # %s" % ["", lines] } end strout end |