Class: Incline::CLI
- Inherits:
-
Object
show all
- Defined in:
- lib/incline/cli.rb,
lib/incline/cli/usage.rb,
lib/incline/cli/errors.rb,
lib/incline/cli/prepare.rb,
lib/incline/cli/version.rb,
lib/incline/cli/prepare/config_ssh.rb,
lib/incline/cli/prepare/install_db.rb,
lib/incline/cli/prepare/ssh_copy_id.rb,
lib/incline/cli/prepare/extend_shell.rb,
lib/incline/cli/prepare/install_ruby.rb,
lib/incline/cli/prepare/install_rails.rb,
lib/incline/cli/prepare/install_rbenv.rb,
lib/incline/cli/prepare/restart_nginx.rb,
lib/incline/cli/prepare/update_system.rb,
lib/incline/cli/prepare/add_deploy_user.rb,
lib/incline/cli/prepare/install_flytrap.rb,
lib/incline/cli/prepare/install_prereqs.rb,
lib/incline/cli/prepare/config_passenger.rb,
lib/incline/cli/prepare/install_passenger.rb,
lib/incline/cli/prepare/create_nginx_utils.rb
Defined Under Namespace
Classes: CliError, Prepare, Usage, UsageError, Version
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
16
17
18
|
# File 'lib/incline/cli.rb', line 16
def initialize
end
|
Class Method Details
.valid_commands ⇒ Object
71
72
73
74
75
|
# File 'lib/incline/cli.rb', line 71
def self.valid_commands
command_list.map do |cmd_info|
[ cmd_info[:method], cmd_info[:klass], cmd_info[:new_params] ]
end
end
|
Instance Method Details
#execute(*args) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/incline/cli.rb', line 20
def execute(*args)
begin
if args.empty? || %w(help /? -? -help --help).include?(args.first)
process_command(:usage)
else
process_command(*args)
end
rescue UsageError => err
STDERR.puts err.message
process_command(:usage, err.command)
rescue CliError => err
STDERR.puts ANSI.code(:red) { 'ERROR:' }
STDERR.puts err.message
rescue RuntimeError => err
STDERR.puts ANSI.code(:red) { 'FATAL ERROR:' }
STDERR.puts err.inspect
end
end
|
#process_command(command, *args) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/incline/cli.rb', line 39
def process_command(command, *args)
command = command.to_sym
cmd_info = self.class.command_list.find{|c| c[:method] == command}
if cmd_info
args = args.dup
command_args = []
cmd_info[:new_params].each do |(type,name)|
if type == :rest
command_args += args
break
elsif type == :req
if args.empty?
raise UsageError, "Missing required parameter '#{name}' for command '#{command}'."
end
command_args << args.delete_at(0)
elsif type == :opt
if args.empty?
break
else
command_args << args.delete_at(0)
end
else
raise UsageError, "Unknown parameter type '#{type}' for command '#{command}'."
end
end
cmd_object = cmd_info[:klass].new(*command_args)
cmd_object.send(:run)
else
raise UsageError, "Unknown command '#{command}'."
end
end
|