Module: TreasureData::Command::List

Defined in:
lib/td/command/list.rb

Defined Under Namespace

Classes: CommandOption

Constant Summary collapse

LIST =
[]
COMMAND =
{}
GUESS =
{}
HELP_EXCLUDE =
['help', 'account']

Class Method Summary collapse

Class Method Details

.add_alias(new_cmd, old_cmd) ⇒ Object



117
118
119
# File 'lib/td/command/list.rb', line 117

def self.add_alias(new_cmd, old_cmd)
  COMMAND[new_cmd] = COMMAND[old_cmd]
end

.add_guess(wrong, correct) ⇒ Object



121
122
123
# File 'lib/td/command/list.rb', line 121

def self.add_guess(wrong, correct)
  GUESS[wrong] = correct
end

.add_list(name, args, description) ⇒ Object



113
114
115
# File 'lib/td/command/list.rb', line 113

def self.add_list(name, args, description)
  LIST << COMMAND[name] = CommandOption.new(name, args, description)
end

.finishupObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/td/command/list.rb', line 166

def self.finishup
  groups = {}
  LIST.each {|op|
    (groups[op.group] ||= []) << op
  }
  groups.each_pair {|group,ops|
    if ops.size > 1 && xop = COMMAND[group].dup
      msg = %[Additional commands, type "#{File.basename($0)} help COMMAND" for more details:\n\n]
      ops.each {|op|
        msg << %[  #{op.usage}\n]
      }
      msg << %[\n]
      xop.message = msg
      COMMAND[group] = xop
    end
  }
end

.get_group(group) ⇒ Object



160
161
162
163
164
# File 'lib/td/command/list.rb', line 160

def self.get_group(group)
  LIST.map {|op|
    op.group == group
  }
end

.get_method(name) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/td/command/list.rb', line 125

def self.get_method(name)
  if op = COMMAND[name]
    name = op.name
    group, action = op.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(op.with_args(args)) }
  end
  nil
end

.get_option(name) ⇒ Object



144
145
146
# File 'lib/td/command/list.rb', line 144

def self.get_option(name)
  COMMAND[name]
end

.show_guess(wrong) ⇒ Object



138
139
140
141
142
# File 'lib/td/command/list.rb', line 138

def self.show_guess(wrong)
  if correct = GUESS[wrong]
    $stderr.puts "Did you mean this?: #{correct}"
  end
end

.show_help(indent = ' ') ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/td/command/list.rb', line 148

def self.show_help(indent='  ')
  before_group = nil
  LIST.each {|op|
    next if HELP_EXCLUDE.include?(op.name)
    if before_group != op.group
      before_group = op.group
      puts ""
    end
    puts "#{indent}#{op.usage}"
  }
end