46
47
48
49
50
51
52
53
54
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/dry-stack/command_line.rb', line 46
def run(args)
params = {}
a, = ARGV.join(' ').split( / -- /)
ARGV.replace a.split if a
ARGV << '-h' if ARGV.empty?
OptionParser.new do |o|
o.version = "#{Dry::Stack::VERSION}"
usage = [
'dry-stack -s stackfile [options] COMMAND',
'cat stackfile | dry-stack COMMAND',
'dry-stack COMMAND < stack.drs'
]
o.banner = "Version: #{o.version}\nUsage:\n\t#{usage.join "\n\t"}"
o.separator ''
o.separator 'Commands:'
COMMANDS.each { |name, cmd| o.separator "#{' ' * 5}#{name} - #{[cmd.help].flatten.join "\n#{' ' * (5+4 + name.size)}" }" }
o.separator ''
o.separator 'Options:'
o.on('-s', '--stack STACK_NAME', 'Stack file')
o.on('-e', '--env', 'Load .env file') { load_env }
o.on('', '--name STACK_NAME', 'Define stack name')
o.on('', '--ingress', 'Generate ingress labels') { true }
o.on('', '--traefik', 'Generate traefik labels') { true }
o.on('', '--traefik-tls', 'Generate traefik tls labels') { true }
o.on('', '--tls-domain domain', 'Domain for the traefik labels')
o.on('', '--host-sed /from/to/', 'Sed ingress host /\\*/dev.*/')
o.on('-n', '--no-env', 'Deprecated') { $stderr.puts 'warning: deprecated option: -n' } o.on('-c', '--configuration name', 'Configuration name')
COMMANDS.values.select{_1.options(o) if _1.respond_to? :options }
o.on('-h', '--help') { puts o; exit }
o.parse! args, into: params
params.transform_keys!{_1.to_s.gsub('-','_').to_sym}
params[:traefik_tls] = true if params[:tls_domain]
params[:traefik] = true unless params.key? :traefik
Dry.cmd_params = params
raise 'Stack file not defined' if $stdin.tty? && !params[:stack]
command = args.shift || ''
raise "Unknown command: #{command}" unless COMMANDS.key?(command.to_sym)
stack_text = File.read(params[:stack]) if params[:stack]
stack_text ||= STDIN.read unless $stdin.tty?
safe_eval stack_text, params
Stack.last_stack.name = params[:name] if params[:name]
COMMANDS[command.to_sym].run Stack.last_stack, params, args,
rescue => e
puts e.message
ENV['DEBUG'] ? raise : exit(1)
end
end
|