Module: Wod::Command
- Extended by:
- Helpers
- Defined in:
- lib/wod/command.rb,
lib/wod/commands/app.rb,
lib/wod/commands/auth.rb,
lib/wod/commands/base.rb,
lib/wod/commands/help.rb,
lib/wod/commands/devices.rb,
lib/wod/commands/version.rb
Defined Under Namespace
Classes: App, Auth, Base, CommandFailed, Devices, Help, InvalidCommand, Version
Class Method Summary
collapse
Methods included from Helpers
ask, display_formatted, error, home_directory, last_page_file, wod_directory
Class Method Details
.parse(command) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/wod/command.rb', line 44
def self.parse(command)
parts = command.split(':')
case parts.size
when 1
begin
return eval("Wod::Command::#{command.capitalize}"), :index
rescue NameError, NoMethodError
return Wod::Command::App, command.to_sym
end
else
begin
const = Wod::Command
command = parts.pop
parts.each { |part| const = const.const_get(part.capitalize) }
return const, command.to_sym
rescue NameError
raise InvalidCommand
end
end
end
|
.run(command, args, retries = 0) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/wod/command.rb', line 13
def self.run(command, args, retries=0)
begin
run_internal 'auth:reauthorize', args.dup if retries > 0
run_internal command, args.dup
rescue InvalidCommand
error "Unknown command. Run 'wod help' for usage information."
rescue Wod::InvalidCredentials
if retries < 3
STDERR.puts "Authentication failure"
run command, args, retries + 1
else
error "Authentication failure"
end
rescue Exception => e
File.open(last_page_file, 'w') do |f|
f.chmod(0600)
f.puts Client.last_page.page.send(:html_body)
end
puts "Error: Last page saved to #{last_page_file}"
raise e
end
end
|
.run_internal(command, args, wod = nil) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/wod/command.rb', line 37
def self.run_internal(command, args, wod=nil)
klass, method = parse command
runner = klass.new args, wod
raise InvalidCommand unless runner.respond_to?(method)
runner.send method
end
|