ec2ctl 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fca3cd233af8d3490fe1413140d69c929b01eb71
4
- data.tar.gz: 81b7947de057b8b75c4ac890319d17a98bf1e5dc
3
+ metadata.gz: b2e08c5db7580a3b3be676e4974d7186c98eacbe
4
+ data.tar.gz: 15c9f9525fc194337ec5ece48ae94fe05cc7282b
5
5
  SHA512:
6
- metadata.gz: 71417debb54cb974406b6e0c54018351d5a1a41714ad5e8012db8b4411f6b5c361530aa797fb50d45fade38c78554f5262ad210f01c34113911a455caff44fe0
7
- data.tar.gz: 73a82751440cf841115c8734a9297ce79da58434843a29d09a2f2c6e4861f2cde82a65256d5100a65cf9cf64236d76d5b0984e390047113f843ed856c04a7d77
6
+ metadata.gz: 68f22cba95a82b4069cc33fef991cd92d01a52f49857f7f2971b78895b7eac3fcbe56b1fc013b23d77900014f18371e20d25e42c6b87ed6169774cb11391026f
7
+ data.tar.gz: 8ffc388529bd49ed70573cd2f107e2446cd0a4999c919a048eeb4ee0ac48de5f64c0a05a9153580a2102eca572f97ee7af85c8424994bf8db63a54803c823c23
data/lib/ec2ctl/cli.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "commander"
2
2
  require "ec2ctl/logger"
3
+ require "pathname"
3
4
 
4
5
  module EC2Ctl
5
6
  class CLI
@@ -7,16 +8,24 @@ module EC2Ctl
7
8
 
8
9
  OptionError = Class.new RuntimeError
9
10
 
11
+ USER_OPTION_FILE_PATH = Pathname.new(ENV["HOME"]) / ".ec2ctlrc"
12
+
13
+ DEFAULT_OPTIONS = {
14
+ "ec2 list" => {
15
+ attributes: %w(instance_id tag:Name instance_type public_dns_name state.name ssm:ping_status),
16
+ },
17
+ }
18
+
10
19
  def run
11
20
  program :name, self.class.to_s
12
21
  program :version, VERSION
13
22
  program :description, "A small command line tool for managing EC2/ELB."
14
23
 
15
- global_option("-V", "--verbose", "Debug output.") {@verbose = true}
16
- global_option("-P", "--pretty", "Pretty JSON output.") {@pretty = true}
17
- global_option("-o", "--output #{EC2Ctl::Logger::VALID_FORMATS}", "Log output format.") {|v| @output_format = v.intern}
18
- global_option("-p", "--profile PROFILE_NAME", "AWS profile name.") {|v| ENV["AWS_PROFILE"] = v}
19
- global_option("-r", "--region REGION_NAME", "AWS region name.") {|v| ENV["AWS_REGION"] = v}
24
+ global_option "-V", "--verbose", "Debug output."
25
+ global_option "-P", "--pretty", "Pretty JSON output."
26
+ global_option "-o", "--output #{EC2Ctl::Logger::VALID_FORMATS}", "Log output format."
27
+ global_option "-p", "--profile PROFILE_NAME", "AWS profile name."
28
+ global_option "-r", "--region REGION_NAME", "AWS region name."
20
29
 
21
30
  default_command :"ec2 list"
22
31
 
@@ -31,7 +40,7 @@ module EC2Ctl
31
40
  c.option "--platform-type Linux|Windows", String, "(Optional) Platform type: `Linux` or `Windows`. Default is `Linux`."
32
41
 
33
42
  c.action do |args, options|
34
- options.default attributes: %w(instance_id tag:Name instance_type public_dns_name state.name ssm:ping_status)
43
+ handle_options c, options
35
44
 
36
45
  invoke options do
37
46
  @client.ec2_list
@@ -47,6 +56,8 @@ module EC2Ctl
47
56
  ssm_options c
48
57
 
49
58
  c.action do |args, options|
59
+ handle_options c, options
60
+
50
61
  invoke options do
51
62
  mandatory options, :commands
52
63
  @client.ec2_execute
@@ -59,6 +70,8 @@ module EC2Ctl
59
70
  c.description = "List load balancers."
60
71
 
61
72
  c.action do |args, options|
73
+ handle_options c, options
74
+
62
75
  invoke options do
63
76
  @client.elb_list
64
77
  end
@@ -72,6 +85,8 @@ module EC2Ctl
72
85
  c.option "-b", "--load-balancer-name VALUE", String, "The name of the load balancer."
73
86
 
74
87
  c.action do |args, options|
88
+ handle_options c, options
89
+
75
90
  invoke options do
76
91
  mandatory options, :load_balancer_name
77
92
  @client.elb_status
@@ -87,6 +102,8 @@ module EC2Ctl
87
102
  c.option "-i", "--instance-ids STRING1,STRING2", Array, "(Optional) The IDs of the instances to attach."
88
103
 
89
104
  c.action do |args, options|
105
+ handle_options c, options
106
+
90
107
  invoke options do
91
108
  mandatory options, :load_balancer_name, :instance_ids
92
109
  @client.elb_attach
@@ -102,6 +119,8 @@ module EC2Ctl
102
119
  c.option "-i", "--instance-ids STRING1,STRING2", Array, "(Optional) The IDs of the instances to detach."
103
120
 
104
121
  c.action do |args, options|
122
+ handle_options c, options
123
+
105
124
  invoke options do
106
125
  mandatory options, :load_balancer_name, :instance_ids
107
126
  @client.elb_detach
@@ -116,6 +135,8 @@ module EC2Ctl
116
135
  elb_execute_options c
117
136
 
118
137
  c.action do |args, options|
138
+ handle_options c, options
139
+
119
140
  invoke options do
120
141
  mandatory options, :load_balancer_name, :commands
121
142
  @client.elb_execute
@@ -130,6 +151,8 @@ module EC2Ctl
130
151
  elb_execute_options c
131
152
 
132
153
  c.action do |args, options|
154
+ handle_options c, options
155
+
133
156
  invoke options do
134
157
  mandatory options, :load_balancer_name, :commands
135
158
  @client.elb_graceful
@@ -241,5 +264,31 @@ module EC2Ctl
241
264
  _command.option "-s", "--search KEY1=VALUE1,KEY2=VALUE2...", Array, "(Optional) The key-value pairs to search instances by Regexp."
242
265
  _command.option "-i", "--instance-ids STRING1,STRING2", Array, "(Optional) The IDs of the instances."
243
266
  end
267
+
268
+ def handle_options(_command, opt)
269
+ default_opt = DEFAULT_OPTIONS[_command.name]
270
+
271
+ user_options = if File.exists? USER_OPTION_FILE_PATH
272
+ require "json"
273
+ JSON.load(File.read(USER_OPTION_FILE_PATH))
274
+ end
275
+
276
+ if user_options && user_options[_command.name]
277
+ user_options[_command.name].each do |k, v|
278
+ default_opt.update k.intern => v
279
+ end
280
+ end
281
+
282
+ opt.default default_opt if default_opt
283
+ handle_global_options opt
284
+ end
285
+
286
+ def handle_global_options(opt)
287
+ @verbose = true if opt.verbose
288
+ @pretty = true if opt.pretty
289
+ @output_format = opt.output if opt.output
290
+ ENV["AWS_PROFILE"] = opt.profile if opt.profile
291
+ ENV["AWS_REGION"] = opt.region if opt.region
292
+ end
244
293
  end
245
294
  end
@@ -1,3 +1,3 @@
1
1
  module EC2Ctl
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2ctl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoriki Yamaguchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2016-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk