Module: SeleniumShots::Command
- Defined in:
- lib/selenium_shots/cli/command.rb,
lib/selenium_shots/cli/commands/app.rb,
lib/selenium_shots/cli/commands/auth.rb,
lib/selenium_shots/cli/commands/base.rb,
lib/selenium_shots/cli/commands/help.rb
Defined Under Namespace
Classes: App, Auth, Base, CommandFailed, Help, InvalidCommand
Class Method Summary
collapse
Class Method Details
.display(msg) ⇒ Object
23
24
25
|
# File 'lib/selenium_shots/cli/command.rb', line 23
def display(msg)
puts(msg)
end
|
.namespaces ⇒ Object
44
45
46
47
48
|
# File 'lib/selenium_shots/cli/command.rb', line 44
def namespaces
@@namespaces ||= Dir["#{File.dirname(__FILE__)}/commands/*"].map do |namespace|
namespace.gsub(/.*\//, '').gsub(/\.rb/, '')
end
end
|
.parse(command) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/selenium_shots/cli/command.rb', line 27
def parse(command)
parts = command.split(':')
case parts.size
when 1
if namespaces.include? command
return command, 'index'
else
return 'app', command
end
when 2
raise InvalidCommand unless namespaces.include? parts[0]
return parts
else
raise InvalidCommand
end
end
|
.run(command, args) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/selenium_shots/cli/command.rb', line 7
def run(command, args)
run_internal(command, args)
rescue InvalidCommand
display "Unknown command. Run 'selenium_shots help' for usage information."
rescue RestClient::Unauthorized
display "Authentication failure. For more information you can go to http://www.seleniumshots.com"
end
|
.run_internal(command, args) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/selenium_shots/cli/command.rb', line 15
def run_internal(command, args)
namespace, command = parse(command)
require "#{namespace}"
klass = SeleniumShots::Command.const_get(namespace.capitalize).new(args)
raise InvalidCommand unless klass.respond_to?(command)
klass.send(command)
end
|