Module: Autoweb::Command
- Extended by:
- UI
- Defined in:
- lib/autoweb/command.rb
Defined Under Namespace
Classes: Base, CommandFailed, InvalidCommand
Class Method Summary
collapse
Methods included from UI
ask, ask_loop, confirm, display, display2, error, format_date, shell
Class Method Details
.parse(command) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/autoweb/command.rb', line 50
def parse(command)
parts = command.split(':')
case parts.size
when 1
begin
return eval("Autoweb::Command::#{command.capitalize}"), :index
end
when 2
begin
return Autoweb::Command.const_get(parts[0].capitalize), parts[1]
rescue NameError
raise InvalidCommand
end
else
raise InvalidCommand
end
end
|
.run(command, args, retries = 0) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/autoweb/command.rb', line 31
def run(command, args, retries=0)
begin
run_internal(command, args.dup)
rescue InvalidCommand
error "Unknown command. Run 'autoweb help' for usage information."
rescue CommandFailed => e
error e.message
rescue Interrupt => e
error "\n[canceled]"
end
end
|
.run_internal(command, args) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/autoweb/command.rb', line 43
def run_internal(command, args)
klass, method = parse(command)
runner = klass.new(args)
raise InvalidCommand unless runner.respond_to?(method)
runner.send(method)
end
|