knife-helper 0.0.5 → 0.1.0

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: 14c6110622c4edde3584a337c98f75abcca3c97c
4
- data.tar.gz: 5077e912b6578899015e76b6080a175ca96eec3b
3
+ metadata.gz: 231c99b7f892f61e0999bcaaf5f7cbbf5d0c0662
4
+ data.tar.gz: 7bd5445511ca8634535b54934dd638e47f4e1e3c
5
5
  SHA512:
6
- metadata.gz: 591747610f3b6fce891af75ebc8aea0ccf12cd9f90e0a78b25935cd4401484b2f26fd9fe2929f55b7018fe224eda8694aee1772eee8c4a986541cc9d6ac257f4
7
- data.tar.gz: 2260af1ce1998386913b6fe673f98acdc6b689991489f41dfb6c777ba67d0894d78e17b61ee95cdb55e4edbba6ba0f82e064c42348e58dc83e3b862c26ad4028
6
+ metadata.gz: c3f9bd07a71b9d90b691fbd7b407da1797b62653c4db8ffe8e44753cb1e2ab67697370dcc6396bbadd673d8521df5ba65ebc50af1cc312554a465fb01316ac7b
7
+ data.tar.gz: 4ba4ad52b24df0590506bc366d46995e623977df8c555e087b811e10ac9109236acf8a1d01f6f24a976ee22a151e6874a3e65d8d2303ae2974eebc887f750c1e
@@ -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 default
17
- - bundle exec knife helper exec default
18
+ - bundle exec knife helper build create
19
+ - bundle exec knife helper exec create -p
@@ -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
- Command name for execution.
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:option
77
- Command options.
111
+ ### commands:options
112
+ Command options.
113
+ Type: `Hash`
78
114
 
79
115
  ## ChangeLog
80
116
  see [CHANGELOG][changelog]
@@ -0,0 +1,6 @@
1
+ option_sets:
2
+ - name: aws
3
+ options:
4
+ aws-access-key-id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
5
+ aws-secret-access-key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
6
+ region: ap-southeast-1
@@ -0,0 +1,14 @@
1
+ ---
2
+ includes:
3
+ - .include.yml
4
+
5
+ settings:
6
+ command_base: bundle exec rake
7
+
8
+ commands:
9
+ - name: create
10
+ command: ec2 server create
11
+ option_sets:
12
+ - aws
13
+ options:
14
+ flavor: t2.micro
@@ -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
- ::Knife::Helper::Config.new(config[:file]).data
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['command']
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
- ::Knife::Helper::Config.new(config[:file]).data
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
- ::Knife::Helper::Config.new(config[:file]).data
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(config)
9
- @base = config['settings']['command_base']
10
- @commands = config['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
- cmd << " #{complete_option(k)}"
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
@@ -6,11 +6,14 @@ module Knife
6
6
  module Helper
7
7
  class Config
8
8
 
9
- attr_reader :data
9
+ attr_reader :settings, :option_sets, :commands
10
10
 
11
11
  def initialize(file=nil)
12
12
  file ||= default_file
13
- @data = load_config(file)
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)
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Helper
3
- VERSION = "0.0.5"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -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(config)
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')).data
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) }
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')).data
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) }
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
@@ -4,8 +4,13 @@ includes:
4
4
  settings:
5
5
  command_base: <%= config[:command_base] %>
6
6
 
7
+ option_sets:
8
+ - name: default
9
+ options:
10
+
7
11
  commands:
8
12
  - name: default
9
13
  command:
10
14
  condition:
15
+ option_sets:
11
16
  options:
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.5
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-13 00:00:00.000000000 Z
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