ec2ctl 0.9.7 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1f3627da0332ac03286a6ef7512e7cd4962939d
4
- data.tar.gz: af12cc4e425a03feccc4cd9f57c740d133a1267d
3
+ metadata.gz: f5b98d7b9d9b2dd4e25ba115a464bbfc026a5bff
4
+ data.tar.gz: 815717a464313caf8711ac002e94abd894d187a2
5
5
  SHA512:
6
- metadata.gz: 8be33c3f39923e42a43585419974eae0ff18c1e04cf1290da2d04ccd4fe660dccb724fd89c4f8d8e79fcdd7cd404158535d8d9591706b44d0629e7f42c82fe0e
7
- data.tar.gz: 2ee01d8a31be5a245f504f47d8e389c20cf086a05365d0587555bfb3515c112603e9889a514a5517cd16758bc0f79e208b90ff2eb1a5a723156c1fa659e11c16
6
+ metadata.gz: f5deacc01b22e5668574e35bedeb9166fad61447cb8ee5c323fc334e3cffb62d91cb358ead0d3760b8f347abaae7bf61e59f3d1ca8fbe1aad86edca50e34cfdd
7
+ data.tar.gz: 830310f036cfa898145f3d46c6d25f548d5fcdde7d864c56960b2b5cb15cd435ce6545be8d1a11a94f44068d01ae646e4c87aba37c512c7bc08f4b5708fb7868
data/lib/ec2ctl/cli.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "commander"
2
2
  require "ec2ctl/logger"
3
3
  require "pathname"
4
+ require "json"
4
5
 
5
6
  module EC2Ctl
6
7
  class CLI
@@ -8,7 +9,7 @@ module EC2Ctl
8
9
 
9
10
  OptionError = Class.new RuntimeError
10
11
 
11
- USER_OPTION_FILE_PATH = Pathname.new(ENV["HOME"]) / ".ec2ctlrc"
12
+ OPTION_FILE_NAME = ".ec2ctlrc".freeze
12
13
 
13
14
  DEFAULT_OPTIONS = {
14
15
  "ec2 list" => {
@@ -167,7 +168,7 @@ module EC2Ctl
167
168
  private
168
169
 
169
170
  def init_client(options)
170
- global_options = %i(
171
+ global_opt = %i(
171
172
  verbose
172
173
  pretty
173
174
  output
@@ -178,7 +179,7 @@ module EC2Ctl
178
179
  help
179
180
  )
180
181
 
181
- @client = EC2Ctl::Client.new options.__hash__.reject {|k, v| global_options.include? k}.merge(logger: logger)
182
+ @client = EC2Ctl::Client.new options.__hash__.reject {|k, v| global_opt.include? k}.merge(logger: logger)
182
183
  end
183
184
 
184
185
  def logger
@@ -268,19 +269,12 @@ module EC2Ctl
268
269
 
269
270
  def handle_options(_command, opt)
270
271
  default_opt = DEFAULT_OPTIONS[_command.name]
272
+ file_opt = options_from_file[_command.name]
271
273
 
272
- user_options = if File.exists? USER_OPTION_FILE_PATH
273
- require "json"
274
- JSON.load(File.read(USER_OPTION_FILE_PATH))
274
+ [default_opt, file_opt].each do |o|
275
+ o.each {|k, v| opt.default k.intern => v} if o
275
276
  end
276
277
 
277
- if user_options && user_options[_command.name]
278
- user_options[_command.name].each do |k, v|
279
- default_opt.update k.intern => v
280
- end
281
- end
282
-
283
- opt.default default_opt if default_opt
284
278
  handle_global_options opt
285
279
  end
286
280
 
@@ -291,5 +285,20 @@ module EC2Ctl
291
285
  ENV["AWS_PROFILE"] = opt.profile if opt.profile
292
286
  ENV["AWS_REGION"] = opt.region if opt.region
293
287
  end
288
+
289
+ def options_from_file
290
+ pathnames = [
291
+ Pathname.new(Dir.pwd).ascend.to_a,
292
+ Pathname.new(Dir.home),
293
+ ].flatten.map do |pathname|
294
+ pathname + OPTION_FILE_NAME
295
+ end
296
+
297
+ pathnames.each do |pathname|
298
+ return JSON.load File.read(pathname) if File.exists? pathname
299
+ end
300
+
301
+ {}
302
+ end
294
303
  end
295
304
  end
@@ -1,3 +1,3 @@
1
1
  module EC2Ctl
2
- VERSION = "0.9.7"
2
+ VERSION = "0.9.8"
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.7
4
+ version: 0.9.8
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-09 00:00:00.000000000 Z
11
+ date: 2016-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk