itamae 1.0.9 → 1.0.10

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: bcebb641f8d69d78034939977dce364a755e8b8e
4
- data.tar.gz: e7fda0c86ecb529cd3c3ff7c75e13de59a898380
3
+ metadata.gz: bf80dc0d09edfc8284cab903ab066deae70f24f7
4
+ data.tar.gz: 3603e62c980190ab27b5b44d776f975315ff6707
5
5
  SHA512:
6
- metadata.gz: a5cf48bd0271dd80ab9e3e6264e51bd227c6eedd1bd0a8a4c656a48c2ff5cbc74df9d94092c4a6ec2b94fa859b9136a7d98bb4deea21d0c0cbcb2227d143fe8b
7
- data.tar.gz: 36792adb8fabf63a1b375dec3c45eaf2569cebecd362a66ad866a51098a55337d981306a61de0be352ee5d275e52d9578778e5b9b3061ea126ae2571febfc3de
6
+ metadata.gz: ee73911856bdf0999914850ffb578c3eaec682417a7572f38f23f17e45f978d32dd10c5eb0af48e1aee0cb676489d56acdca6cfecd107a5bac90c55b9c412096
7
+ data.tar.gz: 47dd8eac7815c35c685b78e2063332d7ebdf1a517b77b66e28c97ba6f7cd3a550d5dee9e49d88d08dff5ec8fd494e87766bb1b1708589235d71db4709dcf3a1e
@@ -9,6 +9,7 @@ require "itamae/node"
9
9
  require "itamae/backend"
10
10
  require "itamae/notification"
11
11
  require "itamae/definition"
12
+ require "itamae/config"
12
13
 
13
14
  module Itamae
14
15
  # Your code goes here...
@@ -6,8 +6,9 @@ module Itamae
6
6
  class_option :log_level, type: :string, aliases: ['-l'], default: 'info'
7
7
  class_option :color, type: :boolean, default: true
8
8
 
9
- def initialize(*args)
10
- super
9
+ def initialize(args, opts, config)
10
+ opts = Config.new(opts).load
11
+ super(args, opts, config)
11
12
 
12
13
  Itamae::Logger.level = ::Logger.const_get(options[:log_level].upcase)
13
14
  Itamae::Logger.formatter.colored = options[:color]
@@ -0,0 +1,46 @@
1
+ require 'yaml'
2
+
3
+ module Itamae
4
+ class Config
5
+ CONFIG_MATCHER = /(-c|--config) +([^ ]+)/
6
+
7
+ def initialize(options)
8
+ @options = options
9
+ end
10
+
11
+ def load
12
+ return @options unless config_given?
13
+
14
+ configs, options = parse_options
15
+ configs.each do |config|
16
+ options += load_config(config)
17
+ end
18
+ options
19
+ end
20
+
21
+ private
22
+
23
+ def parse_options
24
+ configs = []
25
+ parsed_option = joined_options.gsub(CONFIG_MATCHER).each do |match|
26
+ configs << Regexp.last_match[2]
27
+ next ''
28
+ end
29
+ [configs, parsed_option.split(' ')]
30
+ end
31
+
32
+ def load_config(config)
33
+ YAML.load(open(config)).inject([]) do |options, (key, value)|
34
+ options + ["--#{key}", value.to_s]
35
+ end
36
+ end
37
+
38
+ def config_given?
39
+ joined_options =~ CONFIG_MATCHER
40
+ end
41
+
42
+ def joined_options
43
+ @option ||= @options.join(' ')
44
+ end
45
+ end
46
+ end
@@ -1 +1 @@
1
- 1.0.9
1
+ 1.0.10
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Itamae
4
+ describe Config do
5
+ describe '#load' do
6
+ subject { config.load }
7
+
8
+ let!(:config) { described_class.new(options) }
9
+
10
+ context 'without config option' do
11
+ let(:options) { ['-h', 'example.com'] }
12
+
13
+ it { is_expected.to eq(options) }
14
+ end
15
+
16
+ context 'with config option' do
17
+ let(:yaml) { 'port: 22' }
18
+
19
+ before { allow(config).to receive(:open).and_return(yaml) }
20
+
21
+ context 'when short option' do
22
+ let(:options) { ['-h', 'example.com', '-c', 'config.yml'] }
23
+
24
+ it { is_expected.to eq(['-h', 'example.com', '--port', '22']) }
25
+ end
26
+
27
+ context 'when long option' do
28
+ let(:options) { ['-h', 'example.com', '--config', 'config.yml'] }
29
+
30
+ it { is_expected.to eq(['-h', 'example.com', '--port', '22']) }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2014-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -156,6 +156,7 @@ files:
156
156
  - lib/itamae.rb
157
157
  - lib/itamae/backend.rb
158
158
  - lib/itamae/cli.rb
159
+ - lib/itamae/config.rb
159
160
  - lib/itamae/definition.rb
160
161
  - lib/itamae/logger.rb
161
162
  - lib/itamae/node.rb
@@ -187,6 +188,7 @@ files:
187
188
  - spec/integration/recipes/included.rb
188
189
  - spec/integration/recipes/node.json
189
190
  - spec/integration/spec_helper.rb
191
+ - spec/unit/lib/itamae/config_spec.rb
190
192
  - spec/unit/lib/itamae/logger_spec.rb
191
193
  - spec/unit/lib/itamae/node_spec.rb
192
194
  - spec/unit/lib/itamae/recipe_spec.rb
@@ -229,6 +231,7 @@ test_files:
229
231
  - spec/integration/recipes/included.rb
230
232
  - spec/integration/recipes/node.json
231
233
  - spec/integration/spec_helper.rb
234
+ - spec/unit/lib/itamae/config_spec.rb
232
235
  - spec/unit/lib/itamae/logger_spec.rb
233
236
  - spec/unit/lib/itamae/node_spec.rb
234
237
  - spec/unit/lib/itamae/recipe_spec.rb