Class: Kaiser::Cli
Overview
Direct Known Subclasses
Kaiser::Cmds::Attach, Kaiser::Cmds::DbLoad, Kaiser::Cmds::DbReset, Kaiser::Cmds::DbResetHard, Kaiser::Cmds::DbSave, Kaiser::Cmds::Deinit, Kaiser::Cmds::Down, Kaiser::Cmds::Init, Kaiser::Cmds::Login, Kaiser::Cmds::Logs, Kaiser::Cmds::Root, Kaiser::Cmds::Set, Kaiser::Cmds::Show, Kaiser::Cmds::Shutdown, Kaiser::Cmds::Up
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from CliOptions
option, options
Constructor Details
#initialize ⇒ Cli
Returns a new instance of Cli.
13
14
15
|
# File 'lib/kaiser/cli.rb', line 13
def initialize
@use_kaiserfile = true
end
|
Instance Attribute Details
#use_kaiserfile ⇒ Object
Returns the value of attribute use_kaiserfile.
11
12
13
|
# File 'lib/kaiser/cli.rb', line 11
def use_kaiserfile
@use_kaiserfile
end
|
Class Method Details
.all_subcommands_usage ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/kaiser/cli.rb', line 87
def self.all_subcommands_usage
output = ''
@subcommands.each do |name, klass|
name_s = name.to_s
output += "#{name_s}\n"
output += name_s.gsub(/./, '-')
output += "\n"
output += klass.usage
output += "\n\n"
end
output
end
|
.register(name, klass) ⇒ Object
50
51
52
53
|
# File 'lib/kaiser/cli.rb', line 50
def self.register(name, klass)
@subcommands ||= {}
@subcommands[name] = klass.new
end
|
.run_command(name, global_opts) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/kaiser/cli.rb', line 55
def self.run_command(name, global_opts)
cmd = @subcommands[name]
opts = cmd.define_options(global_opts + cmd.class.options)
ARGV.shift
Kaiser::Config.load(Dir.pwd, use_kaiserfile: cmd.use_kaiserfile)
if opts[:quiet]
Config.out = File.open(File::NULL, 'w')
Config.info_out = File.open(File::NULL, 'w')
elsif opts[:verbose] || Config.always_verbose?
Config.out = $stderr
Config.info_out = Kaiser::AfterDotter.new(dotter: Kaiser::Dotter.new)
else
Config.out = Kaiser::Dotter.new
Config.info_out = Kaiser::AfterDotter.new(dotter: Config.out)
end
cmd.set_config
cmd.execute(opts)
end
|
Instance Method Details
#define_options(global_opts = []) ⇒ Object
At first I did this in the constructor but the problem with that is Optimist will parse the entire commandline for the first Cli command registered. That means no matter what you call -h or –help on, it will always return the help for the first subcommand. Fixed this by only running define_options when a command is run. We can’t just run the constructor at that point because we need each Cli class to be constructed in the beginning so we can add their usage text to the output of ‘kaiser -h`.
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/kaiser/cli.rb', line 38
def define_options(global_opts = [])
u = usage
Optimist.options do
banner u
global_opts.each { |o| opt(*o) }
end
end
|
#set_config ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/kaiser/cli.rb', line 17
def set_config
@work_dir = Config.work_dir
@config_dir = Config.work_dir
@config_file = Config.config_file
@kaiserfile = Config.kaiserfile
@config = Config.config
@out = Config.out
@info_out = Config.info_out
@kaiserfile.validate! if @use_kaiserfile
end
|
#start_services ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/kaiser/cli.rb', line 109
def start_services
services.each do |service|
Config.info_out.puts "Starting service: #{service.name}"
run_if_dead(
service.shared_name,
"docker run -d
--name #{service.shared_name}
--network #{Config.config[:networkname]}
#{service.image}"
)
end
end
|
#stop_app ⇒ Object
103
104
105
106
107
|
# File 'lib/kaiser/cli.rb', line 103
def stop_app
Config.info_out.puts 'Stopping application'
killrm app_container_name
stop_services
end
|
#stop_services ⇒ Object
122
123
124
125
126
127
|
# File 'lib/kaiser/cli.rb', line 122
def stop_services
services.each do |service|
Config.info_out.puts "Stopping service: #{service.name}"
killrm service.shared_name
end
end
|