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/, /^aggr/]
- 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
137
138
139
|
# File 'lib/td/command/list.rb', line 137
def self.add_alias(new_cmd, old_cmd)
COMMAND[new_cmd] = COMMAND[old_cmd]
end
|
.add_guess(wrong, correct) ⇒ Object
141
142
143
|
# File 'lib/td/command/list.rb', line 141
def self.add_guess(wrong, correct)
GUESS[wrong] = correct
end
|
.add_list(name, args, description, *examples) ⇒ Object
133
134
135
|
# File 'lib/td/command/list.rb', line 133
def self.add_list(name, args, description, *examples)
LIST << COMMAND[name] = CommandOption.new(name, args, description, examples)
end
|
.cmd_usage(name) ⇒ Object
145
146
147
148
149
150
151
|
# File 'lib/td/command/list.rb', line 145
def self.cmd_usage(name)
if c = COMMAND[name]
c.create_optparse([]).to_s
else
nil
end
end
|
.finishup ⇒ Object
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/td/command/list.rb', line 194
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
188
189
190
191
192
|
# File 'lib/td/command/list.rb', line 188
def self.get_group(group)
LIST.map {|c|
c.group == group
}
end
|
.get_method(name) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/td/command/list.rb', line 153
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)) }
end
nil
end
|
.get_option(name) ⇒ Object
172
173
174
|
# File 'lib/td/command/list.rb', line 172
def self.get_option(name)
COMMAND[name]
end
|
.show_guess(wrong) ⇒ Object
166
167
168
169
170
|
# File 'lib/td/command/list.rb', line 166
def self.show_guess(wrong)
if correct = GUESS[wrong]
$stderr.puts "Did you mean this?: #{correct}"
end
end
|
.show_help(indent = ' ') ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/td/command/list.rb', line 176
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
puts ""
end
puts "#{indent}#{c.usage}"
}
end
|