Module: TreasureData::Command::List
- Defined in:
- lib/td/command/list.rb
Defined Under Namespace
Classes: CommandOption, CommandParser
Constant Summary
collapse
- LIST =
[]
- COMMAND =
{}
- GUESS =
{}
- HELP_EXCLUDE =
[/^help/, /^account/, /^update/, /^user/]
- USAGE_EXCLUDE =
[/bulk_import:upload_part\z/, /bulk_import:delete_part\z/]
Class Method Summary
collapse
Class Method Details
.add_alias(new_cmd, old_cmd) ⇒ Object
147
148
149
|
# File 'lib/td/command/list.rb', line 147
def self.add_alias(new_cmd, old_cmd)
COMMAND[new_cmd] = COMMAND[old_cmd]
end
|
.add_guess(wrong, correct) ⇒ Object
151
152
153
|
# File 'lib/td/command/list.rb', line 151
def self.add_guess(wrong, correct)
GUESS[wrong] = correct
end
|
.add_list(name, args, description, examples = [], cmd_req_conn = true) ⇒ Object
143
144
145
|
# File 'lib/td/command/list.rb', line 143
def self.add_list(name, args, description, examples = [], cmd_req_conn = true)
LIST << COMMAND[name] = CommandOption.new(name, args, description, examples, cmd_req_conn)
end
|
.cmd_usage(name) ⇒ Object
155
156
157
158
159
160
161
|
# File 'lib/td/command/list.rb', line 155
def self.cmd_usage(name)
if c = COMMAND[name]
c.create_optparse([]).to_s
else
nil
end
end
|
.finishup ⇒ Object
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/td/command/list.rb', line 204
def self.finishup
groups = {}
LIST.each {|c|
(groups[c.group] ||= []) << c
}
groups.each_pair {|group,ops|
if ops.size > 1 && c = COMMAND[group]
c = c.dup
msg = %[Additional commands, type "#{File.basename($0)} help COMMAND" for more details:\n\n]
ops.each {|op|
unless USAGE_EXCLUDE.any? {|pattern| pattern =~ op.name }
msg << %[ #{op.usage}\n]
end
}
msg << %[\n]
c.override_message = msg
COMMAND[group] = c
end
}
end
|
.get_group(group) ⇒ Object
198
199
200
201
202
|
# File 'lib/td/command/list.rb', line 198
def self.get_group(group)
LIST.map {|c|
c.group == group
}
end
|
.get_method(name) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/td/command/list.rb', line 163
def self.get_method(name)
if c = COMMAND[name]
name = c.name
group, action = c.group
require 'td/command/common'
require "td/command/#{group}"
cmd = name.gsub(/[\:\-]/, '_')
m = Object.new.extend(Command).method(cmd)
return Proc.new { |args| m.call(c.create_optparse(args)) }, c.req_conn
end
nil
end
|
.get_option(name) ⇒ Object
182
183
184
|
# File 'lib/td/command/list.rb', line 182
def self.get_option(name)
COMMAND[name]
end
|
.show_guess(wrong) ⇒ Object
176
177
178
179
180
|
# File 'lib/td/command/list.rb', line 176
def self.show_guess(wrong)
if correct = GUESS[wrong]
$stderr.puts "Did you mean this?: #{correct}"
end
end
|
.show_help(indent = ' ') ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/td/command/list.rb', line 186
def self.show_help(indent=' ')
before_group = nil
LIST.each {|c|
next if HELP_EXCLUDE.any? {|pattern| pattern =~ c.name }
if before_group != c.group
before_group = c.group
$stdout.puts ""
end
$stdout.puts "#{indent}#{c.usage}"
}
end
|