Module: Kontena
- Defined in:
- lib/kontena_cli.rb,
lib/kontena/util.rb,
lib/kontena/client.rb,
lib/kontena/errors.rb,
lib/kontena/cli/common.rb,
lib/kontena/cli/config.rb,
lib/kontena/cli/spinner.rb,
lib/kontena/cli/version.rb,
lib/kontena/light_prompt.rb,
lib/kontena/stacks_cache.rb,
lib/kontena/stacks_client.rb,
lib/kontena/machine/common.rb,
lib/kontena/plugin_manager.rb,
lib/kontena/cli/bytes_helper.rb,
lib/kontena/cli/grid_options.rb,
lib/kontena/debug_instrumentor.rb,
lib/kontena/cli/table_generator.rb,
lib/kontena/machine/cert_helper.rb,
lib/kontena/machine/random_name.rb,
lib/kontena/cli/browser_launcher.rb,
lib/kontena/plugin_manager/common.rb,
lib/kontena/plugin_manager/loader.rb,
lib/kontena/plugin_manager/cleaner.rb,
lib/kontena/cli/localhost_web_server.rb,
lib/kontena/plugin_manager/installer.rb,
lib/kontena/cli/master/config_command.rb,
lib/kontena/cli/log_formatters/compact.rb,
lib/kontena/plugin_manager/uninstaller.rb,
lib/kontena/cli/services/services_helper.rb,
lib/kontena/cli/log_formatters/strip_color.rb,
lib/kontena/plugin_manager/rubygems_client.rb,
lib/kontena/machine/cloud_config/node_generator.rb,
lib/kontena/callbacks/master/deploy/90_proptip_after_deploy.rb,
lib/kontena/callbacks/master/deploy/04_default_master_version.rb,
lib/kontena/callbacks/master/deploy/01_show_logo_before_deploy.rb,
lib/kontena/callbacks/master/deploy/70_invite_self_after_deploy.rb,
lib/kontena/callbacks/master/deploy/50_authenticate_after_deploy.rb,
lib/kontena/callbacks/auth/01_list_and_select_grid_after_master_auth.rb,
lib/kontena/callbacks/master/01_clear_current_master_after_terminate.rb,
lib/kontena/callbacks/master/deploy/55_create_initial_grid_after_deploy.rb,
lib/kontena/callbacks/master/deploy/56_set_server_provider_after_deploy.rb,
lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb,
lib/kontena/callbacks/master/deploy/40_install_ssl_certificate_after_deploy.rb,
lib/kontena/callbacks/master/deploy/60_configure_auth_provider_after_deploy.rb
Defined Under Namespace
Modules: Callbacks, Cli, Errors, Machine, PluginManager, Stacks, Util
Classes: Callback, Client, Command, DebugInstrumentor, LightPrompt, LocalhostWebServer, MainCommand, StacksCache, StacksClient
Class Method Summary
collapse
Class Method Details
.browserless? ⇒ Boolean
102
103
104
|
# File 'lib/kontena_cli.rb', line 102
def self.browserless?
!!(RUBY_PLATFORM =~ /linux|(?:free|net|open)bsd|solaris|aix|hpux/ && ENV['DISPLAY'].to_s.empty?)
end
|
.cli_root(*joinables) ⇒ Object
143
144
145
146
147
148
149
|
# File 'lib/kontena_cli.rb', line 143
def self.cli_root(*joinables)
if joinables.empty?
File.join(Kontena.root, 'lib/kontena/cli')
else
File.join(Kontena.root, 'lib/kontena/cli', *joinables)
end
end
|
.debug? ⇒ Boolean
167
168
169
|
# File 'lib/kontena_cli.rb', line 167
def self.debug?
!['', 'false'].include?(ENV['CMD_DEBUG'].to_s)
end
|
.home ⇒ Object
82
83
84
85
86
87
|
# File 'lib/kontena_cli.rb', line 82
def self.home
return @home if @home
@home = File.join(Dir.home, '.krates')
Dir.mkdir(@home, 0700) unless File.directory?(@home)
@home
end
|
.log_target ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/kontena_cli.rb', line 66
def self.log_target
return @log_target if @log_target
@log_target = ENV['LOG_TARGET']
if debug?
@log_target ||= $stderr
elsif @log_target.nil?
@log_target = File.join(home, 'krates.log')
end
end
|
.logger ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/kontena_cli.rb', line 151
def self.logger
return @logger if @logger
if log_target.respond_to?(:tty?) && log_target.tty?
logger = Logger.new(log_target)
require 'kontena/cli/log_formatters/compact'
logger.formatter = Kontena::Cli::LogFormatter::Compact.new
else
logger = Logger.new(log_target, 1, 1_048_576)
require 'kontena/cli/log_formatters/strip_color'
logger.formatter = Kontena::Cli::LogFormatter::StripColor.new
end
logger.level = debug? ? Logger::DEBUG : Logger::INFO
logger.progname = 'CLI'
@logger = logger
end
|
.minor_version ⇒ String
90
91
92
|
# File 'lib/kontena_cli.rb', line 90
def self.minor_version
Kontena::Cli::VERSION.split('.')[0..1].join('.')
end
|
.on_windows? ⇒ Boolean
98
99
100
|
# File 'lib/kontena_cli.rb', line 98
def self.on_windows?
ENV['OS'] == 'Windows_NT' && RUBY_PLATFORM !~ /cygwin/
end
|
.pastel ⇒ Object
110
111
112
113
114
|
# File 'lib/kontena_cli.rb', line 110
def self.pastel
return @pastel if @pastel
require 'pastel'
@pastel = Pastel.new(enabled: !simple_terminal?)
end
|
.prompt ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/kontena_cli.rb', line 116
def self.prompt
return @prompt if @prompt
if simple_terminal?
require_relative 'kontena/light_prompt'
klass = Kontena::LightPrompt
else
require 'tty-prompt'
klass = TTY::Prompt
end
@prompt = klass.new(
active_color: :cyan,
help_color: :white,
error_color: :red,
interrupt: :exit,
prefix: pastel.green('> ')
)
end
|
.reset_logger ⇒ Object
78
79
80
|
# File 'lib/kontena_cli.rb', line 78
def self.reset_logger
@log_target, @logger = nil
end
|
.reset_prompt ⇒ Object
135
136
137
|
# File 'lib/kontena_cli.rb', line 135
def self.reset_prompt
@prompt = nil
end
|
.root ⇒ Object
139
140
141
|
# File 'lib/kontena_cli.rb', line 139
def self.root
File.dirname(__dir__)
end
|
.run(*cmdline) ⇒ TrueClass, FalseClass
Run a kontena command and return true if the command did not raise or exit with a non-zero exit code. Raises nothing.
57
58
59
60
61
62
63
64
|
# File 'lib/kontena_cli.rb', line 57
def self.run(*cmdline)
result = run!(*cmdline)
result.nil? ? true : result
rescue SystemExit => ex
ex.status.zero?
rescue
false
end
|
.run!(*cmdline) ⇒ Object
Run a kontena command like it was launched from the command line. Re-raises any exceptions, except a SystemExit with status 0, which is considered a success.
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/kontena_cli.rb', line 32
def self.run!(*cmdline)
if cmdline.first.kind_of?(Array)
command = cmdline.first
elsif cmdline.size == 1 && cmdline.first.include?(' ')
command = cmdline.first.shellsplit
else
command = cmdline
end
logger.debug { "Running Kontena.run(#{command.inspect})" }
result = Kontena::MainCommand.new(File.basename(__FILE__)).run(command)
logger.debug { "Command completed, result: #{result.inspect} status: 0" }
result
rescue SystemExit => ex
logger.debug { "Command caused SystemExit, status: #{ex.status}" }
return true if ex.status.zero?
raise ex
rescue => ex
logger.error { "Command #{cmdline.inspect} exception" }
logger.error { ex }
raise ex
end
|
.simple_terminal? ⇒ Boolean
106
107
108
|
# File 'lib/kontena_cli.rb', line 106
def self.simple_terminal?
ENV['KONTENA_SIMPLE_TERM'] || !$stdout.tty?
end
|
.version ⇒ Object
94
95
96
|
# File 'lib/kontena_cli.rb', line 94
def self.version
"krates/#{Kontena::Cli::VERSION}"
end
|