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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/stack_master/cli.rb', line 20
def execute!
program :name, 'StackMaster'
program :version, StackMaster::VERSION
program :description, 'AWS Stack Management'
global_option '-c', '--config FILE', String, 'Config file to use'
global_option '--changed', 'filter stack selection to only ones that have changed'
global_option '-y', '--yes', 'Run in non-interactive mode answering yes to any prompts' do
StackMaster.non_interactive!
StackMaster.non_interactive_answer = 'y'
end
global_option '-n', '--no', 'Run in non-interactive mode answering no to any prompts' do
StackMaster.non_interactive!
StackMaster.non_interactive_answer = 'n'
end
global_option '-d', '--debug', 'Run in debug mode' do
StackMaster.debug!
end
command :apply do |c|
c.syntax = 'stack_master apply [region_or_alias] [stack_name]'
c.summary = 'Creates or updates a stack'
c.description = "Creates or updates a stack. Shows a diff of the proposed stack's template and parameters. Tails stack events until CloudFormation has completed."
c.example 'update a stack named myapp-vpc in us-east-1', 'stack_master apply us-east-1 myapp-vpc'
c.option '--on-failure ACTION', String, 'Action to take on CREATE_FAILURE. Valid Values: [ DO_NOTHING | ROLLBACK | DELETE ]. Default: ROLLBACK'
c.action do |args, options|
options.defaults config: default_config_file
execute_stacks_command(StackMaster::Commands::Apply, args, options)
end
end
command :outputs do |c|
c.syntax = 'stack_master outputs [region_or_alias] [stack_name]'
c.summary = 'Displays outputs for a stack'
c.description = "Displays outputs for a stack"
c.action do |args, options|
options.defaults config: default_config_file
execute_stacks_command(StackMaster::Commands::Outputs, args, options)
end
end
command :init do |c|
c.syntax = 'stack_master init [region_or_alias] [stack_name]'
c.summary = 'Initialises the expected directory structure and stack_master.yml file'
c.description = 'Initialises the expected directory structure and stack_master.yml file'
c.option('--overwrite', 'Overwrite existing files')
c.action do |args, options|
options.defaults config: default_config_file
unless args.size == 2
say "Invalid arguments. stack_master init [region] [stack_name]"
else
StackMaster::Commands::Init.perform(options.overwrite, *args)
end
end
end
command :diff do |c|
c.syntax = 'stack_master diff [region_or_alias] [stack_name]'
c.summary = "Shows a diff of the proposed stack's template and parameters"
c.description = "Shows a diff of the proposed stack's template and parameters"
c.example 'diff a stack named myapp-vpc in us-east-1', 'stack_master diff us-east-1 myapp-vpc'
c.action do |args, options|
options.defaults config: default_config_file
execute_stacks_command(StackMaster::Commands::Diff, args, options)
end
end
command :events do |c|
c.syntax = 'stack_master events [region_or_alias] [stack_name]'
c.summary = "Shows events for a stack"
c.description = "Shows events for a stack"
c.example 'show events for myapp-vpc in us-east-1', 'stack_master events us-east-1 myapp-vpc'
c.option '--number Integer', Integer, 'Number of recent events to show'
c.option '--all', 'Show all events'
c.option '--tail', 'Tail events'
c.action do |args, options|
options.defaults config: default_config_file
execute_stacks_command(StackMaster::Commands::Events, args, options)
end
end
command :resources do |c|
c.syntax = 'stack_master resources [region] [stack_name]'
c.summary = "Shows stack resources"
c.description = "Shows stack resources"
c.action do |args, options|
options.defaults config: default_config_file
execute_stacks_command(StackMaster::Commands::Resources, args, options)
end
end
command :list do |c|
c.syntax = 'stack_master list'
c.summary = 'List stack definitions'
c.description = 'List stack definitions'
c.action do |args, options|
options.defaults config: default_config_file
say "Invalid arguments." if args.size > 0
config = load_config(options.config)
StackMaster::Commands::ListStacks.perform(config)
end
end
command :validate do |c|
c.syntax = 'stack_master validate [region_or_alias] [stack_name]'
c.summary = 'Validate a template'
c.description = 'Validate a template'
c.example 'validate a stack named myapp-vpc in us-east-1', 'stack_master validate us-east-1 myapp-vpc'
c.action do |args, options|
options.defaults config: default_config_file
execute_stacks_command(StackMaster::Commands::Validate, args, options)
end
end
command :status do |c|
c.syntax = 'stack_master status'
c.summary = 'Check the current status stacks.'
c.description = 'Checks the status of all stacks defined in the stack_master.yml file. Warning this operation can be somewhat slow.'
c.example 'description', 'Check the status of all stack definitions'
c.action do |args, options|
options.defaults config: default_config_file
say "Invalid arguments. stack_master status" and return unless args.size == 0
config = load_config(options.config)
StackMaster::Commands::Status.perform(config)
end
end
command :delete do |c|
c.syntax = 'stack_master delete [region] [stack_name]'
c.summary = 'Delete an existing stack'
c.description = 'Deletes a stack. The stack does not necessarily have to appear in the stack_master.yml file.'
c.example 'description', 'Delete a stack'
c.action do |args, options|
options.default config: default_config_file
unless args.size == 2
say "Invalid arguments. stack_master delete [region] [stack_name]"
return
end
if options.config and File.file?(options.config)
config = load_config(options.config)
region = Utils.underscore_to_hyphen(config.unalias_region(args[0]))
else
region = args[0]
end
StackMaster.cloud_formation_driver.set_region(region)
StackMaster::Commands::Delete.perform(region, args[1])
end
end
run!
end
|