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
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
|
# File 'lib/stack_master/cli.rb', line 15
def execute!
program :name, 'StackMaster'
program :version, '0.0.1'
program :description, 'AWS Stack Management'
global_option '-c', '--config FILE', 'Config file to use'
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.action do |args, options|
execute_stack_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|
execute_stack_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|
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|
execute_stack_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|
execute_stack_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|
execute_stack_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|
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|
execute_stack_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|
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|
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
|