7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
|
# File 'lib/aptible/cli/subcommands/config.rb', line 7
def self.included(thor)
thor.class_eval do
include Helpers::Operation
include Helpers::App
desc 'config', "Print an app's current configuration"
app_options
def config
app = ensure_app(options)
config = app.current_configuration
env = config ? config.env : nil
puts formatted_config(env || {})
end
desc 'config:add', 'Add an ENV variable to an app'
app_options
define_method 'config:add' do |*args|
app = ensure_app(options)
env = (args)
operation = app.create_operation!(type: 'configure', env: env)
puts 'Updating configuration and restarting app...'
attach_to_operation_logs(operation)
end
desc 'config:set', 'Alias for config:add'
app_options
define_method 'config:set' do |*args|
send('config:add', *args)
end
desc 'config:rm', 'Remove an ENV variable from an app'
app_options
define_method 'config:rm' do |*args|
app = ensure_app(options)
env = Hash[args.map do |arg|
validate_env_key!(arg)
[arg, '']
end]
operation = app.create_operation!(type: 'configure', env: env)
puts 'Updating configuration and restarting app...'
attach_to_operation_logs(operation)
end
desc 'config:unset', 'Alias for config:rm'
app_options
define_method 'config:unset' do |*args|
send('config:rm', *args)
end
private
def formatted_config(env)
env = Hash[env.sort]
env.map { |k, v| "#{k}=#{Shellwords.escape(v)}" }.join("\n")
end
end
end
|