itamae 1.0.9 → 1.0.10
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 +4 -4
- data/lib/itamae.rb +1 -0
- data/lib/itamae/cli.rb +3 -2
- data/lib/itamae/config.rb +46 -0
- data/lib/itamae/version.txt +1 -1
- data/spec/unit/lib/itamae/config_spec.rb +35 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf80dc0d09edfc8284cab903ab066deae70f24f7
|
4
|
+
data.tar.gz: 3603e62c980190ab27b5b44d776f975315ff6707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee73911856bdf0999914850ffb578c3eaec682417a7572f38f23f17e45f978d32dd10c5eb0af48e1aee0cb676489d56acdca6cfecd107a5bac90c55b9c412096
|
7
|
+
data.tar.gz: 47dd8eac7815c35c685b78e2063332d7ebdf1a517b77b66e28c97ba6f7cd3a550d5dee9e49d88d08dff5ec8fd494e87766bb1b1708589235d71db4709dcf3a1e
|
data/lib/itamae.rb
CHANGED
data/lib/itamae/cli.rb
CHANGED
@@ -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(
|
10
|
-
|
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
|
data/lib/itamae/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
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.
|
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-
|
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
|