itamae 1.7.0 → 1.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18368b7f1a365a5f69bc861932b70e6caad8f00f
4
- data.tar.gz: 4ebf0701af6779fdf6b9dab09adf9954bf82f733
3
+ metadata.gz: 1638b5d146f89a94ea442567a8d7f54b5e770055
4
+ data.tar.gz: 88b9dbfc9d74db2008e89c3dd31ca4da5fe05640
5
5
  SHA512:
6
- metadata.gz: 207fdcec0840d1fbe014ebea9180e3d9aa99edb76eebf1b2d0e38090f318dac832908cf8c2348abe861ba8a2958243e6d68603a56495f7c06c9261d5e2b00f78
7
- data.tar.gz: 688ba0b4062ee18d648c8cc8729f5757bb9e28d494a38c8af9df0bc7568d12d06bd6b909de53fd2aec2f84b9eb08bf7274bafebdf438b8b7d1a868d7b965c9ce
6
+ metadata.gz: 98f3995c772b038282d7afc6f4741ae1360000bbe3ac022e8bf159f26819c87c4bfbabf7dcaa9384dd62a2adae6b96de324553952ae45ae2a07911a671ea6e45
7
+ data.tar.gz: 655e435f1a1e0976efb9f722dfa9b9b22179374721ef8b4730d9e0306b2cdaef5ae7950aaf85bc660e83463a83ac3838a2f28058e9e30d2ee37d8dc83b36ca90
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v1.8.0
2
+
3
+ Features
4
+
5
+ - [`generate` and `destroy` subcommands to manipulate cookbooks and roles (by @k0kubun)](https://github.com/itamae-kitchen/itamae/pull/176)
6
+
7
+ Improvements
8
+
9
+ - [Fallback to autoload resource plugin (by @k0kubun)](https://github.com/itamae-kitchen/itamae/pull/179)
10
+
1
11
  ## v1.7.0
2
12
 
3
13
  No change
data/lib/itamae.rb CHANGED
@@ -9,11 +9,8 @@ require "itamae/node"
9
9
  require "itamae/backend"
10
10
  require "itamae/notification"
11
11
  require "itamae/definition"
12
- require "itamae/config"
13
12
  require "itamae/ext"
14
-
15
13
  require "itamae/generators"
16
- require "itamae/generators/project"
17
14
 
18
15
  module Itamae
19
16
  # Your code goes here...
data/lib/itamae/cli.rb CHANGED
@@ -3,12 +3,14 @@ require 'thor'
3
3
 
4
4
  module Itamae
5
5
  class CLI < Thor
6
+ GENERATE_TARGETS = %w[cookbook role].freeze
7
+
6
8
  class_option :log_level, type: :string, aliases: ['-l'], default: 'info'
7
9
  class_option :color, type: :boolean, default: true
10
+ class_option :config, type: :string, aliases: ['-c']
8
11
 
9
- def initialize(args, opts, config)
10
- opts = Config.new(opts).load
11
- super(args, opts, config)
12
+ def initialize(*)
13
+ super
12
14
 
13
15
  Itamae.logger.level = ::Logger.const_get(options[:log_level].upcase)
14
16
  Itamae.logger.formatter.colored = options[:color]
@@ -80,5 +82,41 @@ module Itamae
80
82
  generator.invoke_all
81
83
  end
82
84
 
85
+ desc 'generate [cookbook|role] [NAME]', 'Initialize role or cookbook (short-cut alias: "g")'
86
+ map 'g' => 'generate'
87
+ def generate(target, name)
88
+ validate_generate_target!('generate', target)
89
+
90
+ generator = Generators.find(target).new
91
+ generator.destination_root = File.join("#{target}s", name)
92
+ generator.copy_files
93
+ end
94
+
95
+ desc 'destroy [cookbook|role] [NAME]', 'Undo role or cookbook (short-cut alias: "d")'
96
+ map 'd' => 'destroy'
97
+ def destroy(target, name)
98
+ validate_generate_target!('destroy', target)
99
+
100
+ generator = Generators.find(target).new
101
+ generator.destination_root = File.join("#{target}s", name)
102
+ generator.remove_files
103
+ end
104
+
105
+ private
106
+ def options
107
+ @itamae_options ||= super.dup.tap do |options|
108
+ if config = options[:config]
109
+ options.merge!(YAML.load_file(config))
110
+ end
111
+ end
112
+ end
113
+
114
+ def validate_generate_target!(command, target)
115
+ unless GENERATE_TARGETS.include?(target)
116
+ msg = %Q!ERROR: "itamae #{command}" was called with "#{target}" !
117
+ msg << "but expected to be in #{GENERATE_TARGETS.inspect}"
118
+ fail InvocationError, msg
119
+ end
120
+ end
83
121
  end
84
122
  end
@@ -1,4 +1,20 @@
1
+ require "itamae/generators/cookbook"
2
+ require "itamae/generators/project"
3
+ require "itamae/generators/role"
4
+
1
5
  module Itamae
2
6
  module Generators
7
+ def self.find(target)
8
+ case target
9
+ when 'cookbook'
10
+ Cookbook
11
+ when 'project'
12
+ Project
13
+ when 'role'
14
+ Role
15
+ else
16
+ raise "Unexpected target: #{target}"
17
+ end
18
+ end
3
19
  end
4
20
  end
@@ -0,0 +1,22 @@
1
+ require 'thor'
2
+ require 'thor/group'
3
+
4
+ module Itamae
5
+ module Generators
6
+ class Cookbook < Thor::Group
7
+ include Thor::Actions
8
+
9
+ def self.source_root
10
+ File.expand_path('../templates/cookbook', __FILE__)
11
+ end
12
+
13
+ def copy_files
14
+ directory '.'
15
+ end
16
+
17
+ def remove_files
18
+ remove_file '.'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'thor'
2
+ require 'thor/group'
3
+
4
+ module Itamae
5
+ module Generators
6
+ class Role < Thor::Group
7
+ include Thor::Actions
8
+
9
+ def self.source_root
10
+ File.expand_path('../templates/role', __FILE__)
11
+ end
12
+
13
+ def copy_files
14
+ directory '.'
15
+ end
16
+
17
+ def remove_files
18
+ remove_file '.'
19
+ end
20
+ end
21
+ end
22
+ end
File without changes
File without changes
@@ -34,11 +34,20 @@ module Itamae
34
34
  begin
35
35
  ::Itamae::Plugin::Resource.const_get(to_camel_case(method.to_s))
36
36
  rescue NameError
37
- raise Error, "#{method} resource is missing."
37
+ autoload_plugin_resource(method)
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
+ def autoload_plugin_resource(method)
43
+ begin
44
+ require "itamae/plugin/resource/#{method}"
45
+ ::Itamae::Plugin::Resource.const_get(to_camel_case(method.to_s))
46
+ rescue LoadError, NameError
47
+ raise Error, "#{method} resource is missing."
48
+ end
49
+ end
50
+
42
51
  def define_resource(name, klass)
43
52
  class_name = to_camel_case(name.to_s)
44
53
  if Resource.const_defined?(class_name)
@@ -1 +1 @@
1
- 1.7.0
1
+ 1.8.0
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.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-06 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -205,15 +205,22 @@ files:
205
205
  - lib/itamae.rb
206
206
  - lib/itamae/backend.rb
207
207
  - lib/itamae/cli.rb
208
- - lib/itamae/config.rb
209
208
  - lib/itamae/definition.rb
210
209
  - lib/itamae/ext.rb
211
210
  - lib/itamae/ext/specinfra.rb
212
211
  - lib/itamae/generators.rb
212
+ - lib/itamae/generators/cookbook.rb
213
213
  - lib/itamae/generators/project.rb
214
+ - lib/itamae/generators/role.rb
215
+ - lib/itamae/generators/templates/cookbook/default.rb
216
+ - lib/itamae/generators/templates/cookbook/files/.keep
217
+ - lib/itamae/generators/templates/cookbook/templates/.keep
214
218
  - lib/itamae/generators/templates/project/Gemfile
215
219
  - lib/itamae/generators/templates/project/cookbooks/.keep
216
220
  - lib/itamae/generators/templates/project/roles/.keep
221
+ - lib/itamae/generators/templates/role/default.rb
222
+ - lib/itamae/generators/templates/role/files/.keep
223
+ - lib/itamae/generators/templates/role/templates/.keep
217
224
  - lib/itamae/logger.rb
218
225
  - lib/itamae/node.rb
219
226
  - lib/itamae/notification.rb
@@ -254,7 +261,6 @@ files:
254
261
  - spec/integration/recipes/templates/template_auto.erb
255
262
  - spec/integration/spec_helper.rb
256
263
  - spec/unit/lib/itamae/backend_spec.rb
257
- - spec/unit/lib/itamae/config_spec.rb
258
264
  - spec/unit/lib/itamae/node_spec.rb
259
265
  - spec/unit/lib/itamae/recipe_spec.rb
260
266
  - spec/unit/lib/itamae/resource/base_spec.rb
@@ -303,7 +309,6 @@ test_files:
303
309
  - spec/integration/recipes/templates/template_auto.erb
304
310
  - spec/integration/spec_helper.rb
305
311
  - spec/unit/lib/itamae/backend_spec.rb
306
- - spec/unit/lib/itamae/config_spec.rb
307
312
  - spec/unit/lib/itamae/node_spec.rb
308
313
  - spec/unit/lib/itamae/recipe_spec.rb
309
314
  - spec/unit/lib/itamae/resource/base_spec.rb
data/lib/itamae/config.rb DELETED
@@ -1,46 +0,0 @@
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,35 +0,0 @@
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