knife-helper 0.0.5 → 0.1.0
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/.travis.yml +4 -2
- data/CHANGELOG.md +5 -0
- data/README.md +41 -5
- data/integration_test/.include.yml +6 -0
- data/integration_test/.knife.helper.yml +14 -0
- data/lib/chef/knife/helper_build.rb +5 -2
- data/lib/chef/knife/helper_exec.rb +4 -1
- data/lib/chef/knife/helper_list.rb +5 -2
- data/lib/knife/helper/commands.rb +25 -5
- data/lib/knife/helper/config.rb +5 -2
- data/lib/knife/helper/version.rb +1 -1
- data/spec/knife/helper/commands_spec.rb +45 -1
- data/spec/knife/helper/config_spec.rb +16 -16
- data/templates/helper.yml.erb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 231c99b7f892f61e0999bcaaf5f7cbbf5d0c0662
|
4
|
+
data.tar.gz: 7bd5445511ca8634535b54934dd638e47f4e1e3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3f9bd07a71b9d90b691fbd7b407da1797b62653c4db8ffe8e44753cb1e2ab67697370dcc6396bbadd673d8521df5ba65ebc50af1cc312554a465fb01316ac7b
|
7
|
+
data.tar.gz: 4ba4ad52b24df0590506bc366d46995e623977df8c555e087b811e10ac9109236acf8a1d01f6f24a976ee22a151e6874a3e65d8d2303ae2974eebc887f750c1e
|
data/.travis.yml
CHANGED
@@ -12,6 +12,8 @@ matrix:
|
|
12
12
|
script:
|
13
13
|
- bundle exec rake
|
14
14
|
- bundle exec knife helper init -B -L
|
15
|
+
- cp -f integration_test/.knife.helper.yml ./
|
16
|
+
- cp -f integration_test/.include.yml ./
|
15
17
|
- bundle exec knife helper list
|
16
|
-
- bundle exec knife helper build
|
17
|
-
- bundle exec knife helper exec
|
18
|
+
- bundle exec knife helper build create
|
19
|
+
- bundle exec knife helper exec create -p
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 0.1.0
|
2
|
+
|
3
|
+
* Support set of options [#1]
|
4
|
+
|
1
5
|
## 0.0.5
|
2
6
|
|
3
7
|
* Add `build` subcommand (Previously was `list`)
|
@@ -21,6 +25,7 @@
|
|
21
25
|
* Initial release
|
22
26
|
|
23
27
|
<!--- The following link definition list is generated by PimpMyChangelog --->
|
28
|
+
[#1]: https://github.com/marcy-terui/knife-helper/issues/1
|
24
29
|
[#2]: https://github.com/marcy-terui/knife-helper/issues/2
|
25
30
|
[#4]: https://github.com/marcy-terui/knife-helper/issues/4
|
26
31
|
[@sawanoboly]: https://github.com/sawanoboly
|
data/README.md
CHANGED
@@ -35,6 +35,25 @@ $ knife helper init (options)
|
|
35
35
|
-L, --librarian Generate Cheffile
|
36
36
|
```
|
37
37
|
|
38
|
+
### knife helper list
|
39
|
+
List all command names (and options)
|
40
|
+
|
41
|
+
```
|
42
|
+
$ knife helper init (options)
|
43
|
+
-a, --all Print all commands and options
|
44
|
+
-f, --file FILE Path to config file(yaml)
|
45
|
+
-F, --format FORMAT Which format to use for output
|
46
|
+
```
|
47
|
+
|
48
|
+
### knife helper build
|
49
|
+
Build and output some command that built from the configuration file.
|
50
|
+
|
51
|
+
```
|
52
|
+
$ knife helper build REGEX (option)
|
53
|
+
-f, --file FILE Path to config file(yaml)
|
54
|
+
-F, --format FORMAT Which format to use for output
|
55
|
+
```
|
56
|
+
|
38
57
|
### knife helper exec
|
39
58
|
Execute some command that built from the configuration file.
|
40
59
|
|
@@ -54,6 +73,10 @@ includes:
|
|
54
73
|
settings:
|
55
74
|
command_base: /home/marcy/.rbenv/versions/2.1.5/bin/knife
|
56
75
|
|
76
|
+
option_sets:
|
77
|
+
- name: default
|
78
|
+
options:
|
79
|
+
|
57
80
|
commands:
|
58
81
|
- name: default
|
59
82
|
command: help
|
@@ -62,19 +85,32 @@ commands:
|
|
62
85
|
```
|
63
86
|
|
64
87
|
### includes
|
65
|
-
Include some external configuration files.
|
88
|
+
Include some external configuration files.
|
89
|
+
Type: `Array`
|
90
|
+
|
91
|
+
### option_sets:name
|
92
|
+
Name of options for use commands.
|
93
|
+
Type: `String`
|
94
|
+
|
95
|
+
### commands:options
|
96
|
+
Set od options.
|
97
|
+
Type: `Hash`
|
66
98
|
|
67
99
|
### settings:command_base
|
68
100
|
Path to `knife` execution script.
|
101
|
+
Type: `String`
|
69
102
|
|
70
103
|
### commands:name
|
71
|
-
|
104
|
+
Name of command for execution.
|
105
|
+
Type: `String`
|
72
106
|
|
73
107
|
### commands:condition
|
74
|
-
Condition for search and execute command.
|
108
|
+
Condition for search and execute command.
|
109
|
+
Type: `String`
|
75
110
|
|
76
|
-
### commands:
|
77
|
-
Command options.
|
111
|
+
### commands:options
|
112
|
+
Command options.
|
113
|
+
Type: `Hash`
|
78
114
|
|
79
115
|
## ChangeLog
|
80
116
|
see [CHANGELOG][changelog]
|
@@ -15,8 +15,11 @@ class Chef
|
|
15
15
|
:default => nil
|
16
16
|
|
17
17
|
def run
|
18
|
+
conf = ::Knife::Helper::Config.new(config[:file])
|
18
19
|
commands = ::Knife::Helper::Commands.new(
|
19
|
-
|
20
|
+
conf.settings['command_base'],
|
21
|
+
conf.commands,
|
22
|
+
conf.option_sets
|
20
23
|
)
|
21
24
|
unless @name_args.empty?
|
22
25
|
cm = commands.commands.select{|c| Regexp.new(@name_args.first).match(c['name']) }
|
@@ -25,7 +28,7 @@ class Chef
|
|
25
28
|
end
|
26
29
|
hash = {}
|
27
30
|
cm.map! do |c|
|
28
|
-
hash[c['name']] = c['
|
31
|
+
hash[c['name']] = commands.build(c['name'])
|
29
32
|
end
|
30
33
|
output(ui.presenter.format_for_display(hash))
|
31
34
|
end
|
@@ -22,8 +22,11 @@ class Chef
|
|
22
22
|
:default => nil
|
23
23
|
|
24
24
|
def run
|
25
|
+
conf = ::Knife::Helper::Config.new(config[:file])
|
25
26
|
commands = ::Knife::Helper::Commands.new(
|
26
|
-
|
27
|
+
conf.settings['command_base'],
|
28
|
+
conf.commands,
|
29
|
+
conf.option_sets
|
27
30
|
)
|
28
31
|
@name_args.each do |cmd|
|
29
32
|
if config[:print_command]
|
@@ -6,7 +6,7 @@ class Chef
|
|
6
6
|
class Knife
|
7
7
|
class HelperList < Chef::Knife
|
8
8
|
|
9
|
-
banner "knife helper list"
|
9
|
+
banner "knife helper list (options)"
|
10
10
|
|
11
11
|
option :file,
|
12
12
|
:short => "-f FILE",
|
@@ -22,8 +22,11 @@ class Chef
|
|
22
22
|
:default => false
|
23
23
|
|
24
24
|
def run
|
25
|
+
conf = ::Knife::Helper::Config.new(config[:file])
|
25
26
|
::Knife::Helper::Commands.new(
|
26
|
-
|
27
|
+
conf.settings['command_base'],
|
28
|
+
conf.commands,
|
29
|
+
conf.option_sets
|
27
30
|
).commands.each do |c|
|
28
31
|
if config[:all]
|
29
32
|
output(ui.presenter.format_for_display(c))
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'chef/mixin/deep_merge'
|
1
2
|
|
2
3
|
module Knife
|
3
4
|
module Helper
|
@@ -5,9 +6,10 @@ module Knife
|
|
5
6
|
|
6
7
|
attr_reader :commands
|
7
8
|
|
8
|
-
def initialize(
|
9
|
-
@base =
|
10
|
-
@commands =
|
9
|
+
def initialize(base, commands, option_sets)
|
10
|
+
@base = base
|
11
|
+
@commands = commands
|
12
|
+
@option_sets = option_sets
|
11
13
|
end
|
12
14
|
|
13
15
|
def build(name)
|
@@ -17,12 +19,25 @@ module Knife
|
|
17
19
|
cmd = @base
|
18
20
|
cmd << " #{c['command']}" if c.has_key?('command')
|
19
21
|
cmd << " '#{c['condition']}'" if c.has_key?('condition') && c['condition']
|
22
|
+
options = {}
|
23
|
+
option_sets = {}
|
24
|
+
if c['option_sets'].is_a?(Array)
|
25
|
+
c['option_sets'].each do |opts|
|
26
|
+
option_set(opts).each do |k,v|
|
27
|
+
option_sets[k] = v
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
20
31
|
if c['options'].is_a?(Hash)
|
21
32
|
c['options'].each do |k,v|
|
22
|
-
|
23
|
-
cmd << " #{v}" if v
|
33
|
+
options[k] = v
|
24
34
|
end
|
25
35
|
end
|
36
|
+
options = Chef::Mixin::DeepMerge.deep_merge(options, option_sets)
|
37
|
+
options.each do |k,v|
|
38
|
+
cmd << " #{complete_option(k)}"
|
39
|
+
cmd << " #{v}" if v
|
40
|
+
end
|
26
41
|
break
|
27
42
|
end
|
28
43
|
end
|
@@ -40,6 +55,11 @@ module Knife
|
|
40
55
|
"-#{opt}"
|
41
56
|
end
|
42
57
|
end
|
58
|
+
|
59
|
+
def option_set(name)
|
60
|
+
@option_sets.each {|opts| return opts['options'] if name == opts['name'] }
|
61
|
+
Hash.new
|
62
|
+
end
|
43
63
|
end
|
44
64
|
end
|
45
65
|
end
|
data/lib/knife/helper/config.rb
CHANGED
@@ -6,11 +6,14 @@ module Knife
|
|
6
6
|
module Helper
|
7
7
|
class Config
|
8
8
|
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :settings, :option_sets, :commands
|
10
10
|
|
11
11
|
def initialize(file=nil)
|
12
12
|
file ||= default_file
|
13
|
-
|
13
|
+
conf = load_config(file)
|
14
|
+
@settings = conf['settings']
|
15
|
+
@option_sets = conf['option_sets']
|
16
|
+
@commands = conf['commands']
|
14
17
|
end
|
15
18
|
|
16
19
|
def load_config(file)
|
data/lib/knife/helper/version.rb
CHANGED
@@ -3,7 +3,11 @@ require 'knife/helper/commands'
|
|
3
3
|
|
4
4
|
describe Knife::Helper::Commands do
|
5
5
|
before do
|
6
|
-
@cmd = Knife::Helper::Commands.new(
|
6
|
+
@cmd = Knife::Helper::Commands.new(
|
7
|
+
config['settings']['command_base'],
|
8
|
+
config['commands'],
|
9
|
+
config['option_sets']
|
10
|
+
)
|
7
11
|
end
|
8
12
|
|
9
13
|
let(:config) do
|
@@ -11,6 +15,20 @@ describe Knife::Helper::Commands do
|
|
11
15
|
'settings' => {
|
12
16
|
'command_base' => '/test/knife'
|
13
17
|
},
|
18
|
+
'option_sets' => [
|
19
|
+
{
|
20
|
+
'name' => 'test_set01',
|
21
|
+
'options' => {
|
22
|
+
'i' => "~/.ssh/knife-helper-example.pem"
|
23
|
+
}
|
24
|
+
},
|
25
|
+
{
|
26
|
+
'name' => 'test_set02',
|
27
|
+
'options' => {
|
28
|
+
'x' => "ec2-user"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
],
|
14
32
|
'commands' => [
|
15
33
|
{
|
16
34
|
'name' => 'knife-zero',
|
@@ -22,6 +40,24 @@ describe Knife::Helper::Commands do
|
|
22
40
|
'attribute' => 'ipaddress'
|
23
41
|
}
|
24
42
|
},
|
43
|
+
{
|
44
|
+
'name' => 'knife-zero-opts-1',
|
45
|
+
'command' => 'zero chef_client',
|
46
|
+
'condition' => 'name:*',
|
47
|
+
'option_sets' => ['test_set01'],
|
48
|
+
'options' => {}
|
49
|
+
},
|
50
|
+
{
|
51
|
+
'name' => 'knife-zero-opts-2',
|
52
|
+
'command' => 'zero chef_client',
|
53
|
+
'condition' => 'name:*',
|
54
|
+
'option_sets' => ['test_set01', 'test_set02'],
|
55
|
+
'options' => {
|
56
|
+
'sudo' => nil,
|
57
|
+
'x' => 'ubuntu',
|
58
|
+
'attribute' => 'ipaddress'
|
59
|
+
}
|
60
|
+
},
|
25
61
|
{
|
26
62
|
'name' => 'help',
|
27
63
|
'command' => 'help',
|
@@ -41,6 +77,14 @@ describe Knife::Helper::Commands do
|
|
41
77
|
expect(@cmd.build('help')).to eq(
|
42
78
|
'/test/knife help')
|
43
79
|
end
|
80
|
+
example do
|
81
|
+
expect(@cmd.build('knife-zero-opts-1')).to eq(
|
82
|
+
'/test/knife zero chef_client \'name:*\' -i ~/.ssh/knife-helper-example.pem')
|
83
|
+
end
|
84
|
+
example do
|
85
|
+
expect(@cmd.build('knife-zero-opts-2')).to eq(
|
86
|
+
'/test/knife zero chef_client \'name:*\' -i ~/.ssh/knife-helper-example.pem -x ubuntu --sudo --attribute ipaddress')
|
87
|
+
end
|
44
88
|
end
|
45
89
|
|
46
90
|
describe '#complete_option' do
|
@@ -4,24 +4,24 @@ require 'knife/helper/config'
|
|
4
4
|
describe Knife::Helper::Config do
|
5
5
|
|
6
6
|
describe 'normal' do
|
7
|
-
conf = Knife::Helper::Config.new(test_file_path('normal.yml'))
|
8
|
-
example { expect(conf
|
9
|
-
example { expect(conf
|
10
|
-
example { expect(conf
|
11
|
-
example { expect(conf
|
12
|
-
example { expect(conf
|
7
|
+
conf = Knife::Helper::Config.new(test_file_path('normal.yml'))
|
8
|
+
example { expect(conf.settings).to include('command_base' => 'bundle exec knife') }
|
9
|
+
example { expect(conf.commands.first).to include('name' => 'test') }
|
10
|
+
example { expect(conf.commands.first).to include('condition' => 'chef_environment:test') }
|
11
|
+
example { expect(conf.commands.first['options']).to include('ssh-user' => 'ec2-user') }
|
12
|
+
example { expect(conf.commands.first['options']).to include('sudo' => nil) }
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'merge' do
|
16
|
-
conf = Knife::Helper::Config.new(test_file_path('merge.yml'))
|
17
|
-
example { expect(conf
|
18
|
-
example { expect(conf
|
19
|
-
example { expect(conf
|
20
|
-
example { expect(conf
|
21
|
-
example { expect(conf
|
22
|
-
example { expect(conf
|
23
|
-
example { expect(conf
|
24
|
-
example { expect(conf
|
25
|
-
example { expect(conf
|
16
|
+
conf = Knife::Helper::Config.new(test_file_path('merge.yml'))
|
17
|
+
example { expect(conf.settings).to include('command_base' => 'bundle exec knife') }
|
18
|
+
example { expect(conf.option_sets.first).to include('name' => 'test_set') }
|
19
|
+
example { expect(conf.settings).to include('test01' => 'value01') }
|
20
|
+
example { expect(conf.settings).to include('test02' => 'overwrited') }
|
21
|
+
example { expect(conf.settings).to include('test03' => 'value03') }
|
22
|
+
example { expect(conf.commands.first).to include('name' => 'test') }
|
23
|
+
example { expect(conf.commands.first).to include('condition' => 'chef_environment:test') }
|
24
|
+
example { expect(conf.commands.first['options']).to include('ssh-user' => 'ec2-user') }
|
25
|
+
example { expect(conf.commands.first['options']).to include('sudo' => nil) }
|
26
26
|
end
|
27
27
|
end
|
data/templates/helper.yml.erb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masashi Terui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -109,6 +109,8 @@ files:
|
|
109
109
|
- LICENSE.txt
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
|
+
- integration_test/.include.yml
|
113
|
+
- integration_test/.knife.helper.yml
|
112
114
|
- knife-helper.gemspec
|
113
115
|
- lib/chef/knife/helper_build.rb
|
114
116
|
- lib/chef/knife/helper_exec.rb
|