berkshelf 2.0.0.beta → 2.0.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.
Files changed (92) hide show
  1. data/CHANGELOG.md +19 -1
  2. data/CONTRIBUTING.md +1 -3
  3. data/Gemfile +0 -20
  4. data/Guardfile +3 -3
  5. data/LICENSE +6 -5
  6. data/README.md +1 -0
  7. data/Thorfile +48 -67
  8. data/berkshelf.gemspec +48 -37
  9. data/features/apply_command.feature +17 -11
  10. data/features/config.feature +11 -11
  11. data/features/configure_command.feature +8 -8
  12. data/features/contingent_command.feature +37 -8
  13. data/features/cookbook_command.feature +17 -14
  14. data/features/groups_install.feature +24 -20
  15. data/features/install_command.feature +24 -33
  16. data/features/licenses.feature +112 -0
  17. data/features/list_command.feature +17 -5
  18. data/features/lockfile.feature +307 -188
  19. data/features/outdated_command.feature +1 -4
  20. data/features/package_command.feature +41 -19
  21. data/features/shelf/list.feature +39 -0
  22. data/features/shelf/show.feature +152 -0
  23. data/features/shelf/uninstall.feature +103 -0
  24. data/features/show_command.feature +49 -17
  25. data/features/step_definitions/filesystem_steps.rb +12 -3
  26. data/features/step_definitions/utility_steps.rb +0 -1
  27. data/features/support/env.rb +11 -4
  28. data/features/update_command.feature +22 -10
  29. data/features/upload_command.feature +174 -127
  30. data/features/vendor_install.feature +6 -6
  31. data/generator_files/Berksfile.erb +1 -1
  32. data/generator_files/metadata.rb.erb +7 -7
  33. data/lib/berkshelf.rb +39 -27
  34. data/lib/berkshelf/base_generator.rb +2 -3
  35. data/lib/berkshelf/berksfile.rb +69 -17
  36. data/lib/berkshelf/cached_cookbook.rb +17 -1
  37. data/lib/berkshelf/chef.rb +2 -4
  38. data/lib/berkshelf/chef/config.rb +51 -75
  39. data/lib/berkshelf/chef/cookbook.rb +1 -2
  40. data/lib/berkshelf/chef/cookbook/chefignore.rb +1 -1
  41. data/lib/berkshelf/cli.rb +144 -194
  42. data/lib/berkshelf/command.rb +11 -12
  43. data/lib/berkshelf/commands/shelf.rb +130 -0
  44. data/lib/berkshelf/commands/test_command.rb +11 -0
  45. data/lib/berkshelf/community_rest.rb +1 -2
  46. data/lib/berkshelf/config.rb +14 -10
  47. data/lib/berkshelf/cookbook_generator.rb +30 -24
  48. data/lib/berkshelf/cookbook_source.rb +1 -1
  49. data/lib/berkshelf/cookbook_store.rb +0 -1
  50. data/lib/berkshelf/core_ext.rb +1 -1
  51. data/lib/berkshelf/core_ext/file.rb +1 -1
  52. data/lib/berkshelf/downloader.rb +3 -1
  53. data/lib/berkshelf/errors.rb +128 -53
  54. data/lib/berkshelf/formatters.rb +2 -6
  55. data/lib/berkshelf/formatters/human_readable.rb +8 -2
  56. data/lib/berkshelf/formatters/json.rb +7 -1
  57. data/lib/berkshelf/formatters/null.rb +0 -1
  58. data/lib/berkshelf/git.rb +16 -16
  59. data/lib/berkshelf/init_generator.rb +28 -26
  60. data/lib/berkshelf/location.rb +12 -11
  61. data/lib/berkshelf/locations/chef_api_location.rb +2 -2
  62. data/lib/berkshelf/locations/git_location.rb +0 -1
  63. data/lib/berkshelf/locations/github_location.rb +0 -1
  64. data/lib/berkshelf/locations/path_location.rb +1 -2
  65. data/lib/berkshelf/locations/site_location.rb +3 -2
  66. data/lib/berkshelf/lockfile.rb +29 -10
  67. data/lib/berkshelf/mixin/config.rb +155 -0
  68. data/lib/berkshelf/mixin/logging.rb +0 -1
  69. data/lib/berkshelf/mixin/shellout.rb +71 -0
  70. data/lib/berkshelf/resolver.rb +7 -4
  71. data/lib/berkshelf/test.rb +1 -3
  72. data/lib/berkshelf/ui.rb +8 -4
  73. data/lib/berkshelf/version.rb +1 -1
  74. data/lib/thor/monkies/shell.rb +0 -1
  75. data/spec/config/berkshelf.pem +27 -0
  76. data/spec/config/knife.rb +12 -0
  77. data/spec/config/validator.pem +27 -0
  78. data/spec/spec_helper.rb +4 -8
  79. data/spec/support/chef_api.rb +14 -9
  80. data/spec/support/chef_server.rb +3 -4
  81. data/spec/unit/berkshelf/berksfile_spec.rb +1 -1
  82. data/spec/unit/berkshelf/cookbook_generator_spec.rb +12 -6
  83. data/spec/unit/berkshelf/cookbook_source_spec.rb +13 -1
  84. data/spec/unit/berkshelf/init_generator_spec.rb +5 -0
  85. data/spec/unit/chef/config_spec.rb +9 -10
  86. metadata +216 -93
  87. data/features/info_command.feature +0 -39
  88. data/features/open_command.feature +0 -36
  89. data/lib/berkshelf/cli_commands/test_command.rb +0 -11
  90. data/lib/berkshelf/mixin.rb +0 -10
  91. data/lib/berkshelf/mixin/path_helpers.rb +0 -30
  92. data/spec/support/knife.rb +0 -18
@@ -1,6 +1,5 @@
1
1
  module Berkshelf::Chef
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  module Cookbook
4
- autoload :Chefignore, 'berkshelf/chef/cookbook/chefignore'
3
+ require_relative 'cookbook/chefignore'
5
4
  end
6
5
  end
@@ -30,7 +30,7 @@ module Berkshelf::Chef::Cookbook
30
30
  end
31
31
  end
32
32
 
33
- FILENAME = "chefignore".freeze
33
+ FILENAME = 'chefignore'.freeze
34
34
  COMMENTS_AND_WHITESPACE = /^\s*(?:#.*)?$/
35
35
 
36
36
  attr_reader :ignores
@@ -1,7 +1,12 @@
1
1
  require 'berkshelf'
2
+ require_relative 'config'
3
+ require_relative 'init_generator'
4
+ require_relative 'cookbook_generator'
5
+
6
+ require 'berkshelf/commands/test_command'
7
+ require 'berkshelf/commands/shelf'
2
8
 
3
9
  module Berkshelf
4
- # @author Jamie Winsor <reset@riotgames.com>
5
10
  class Cli < Thor
6
11
  class << self
7
12
  def dispatch(meth, given_args, given_opts, config)
@@ -15,7 +20,7 @@ module Berkshelf
15
20
  end
16
21
  else
17
22
  super
18
- Berkshelf.formatter.cleanup_hook unless config[:current_command].name == "help"
23
+ Berkshelf.formatter.cleanup_hook unless config[:current_command].name == 'help'
19
24
  end
20
25
  end
21
26
  end
@@ -25,7 +30,7 @@ module Berkshelf
25
30
 
26
31
  if @options[:config]
27
32
  unless File.exist?(@options[:config])
28
- raise BerksConfigNotFound, "You specified a path to a configuration file that did not exist: '#{@options[:config]}'"
33
+ raise ConfigNotFound.new(:berkshelf, @options[:config])
29
34
  end
30
35
  Berkshelf::Config.path = @options[:config]
31
36
  end
@@ -42,7 +47,7 @@ module Berkshelf
42
47
  @options = options.dup # unfreeze frozen options Hash from Thor
43
48
  end
44
49
 
45
- namespace "berkshelf"
50
+ namespace 'berkshelf'
46
51
 
47
52
  map 'in' => :install
48
53
  map 'up' => :upload
@@ -55,52 +60,52 @@ module Berkshelf
55
60
 
56
61
  class_option :config,
57
62
  type: :string,
58
- desc: "Path to Berkshelf configuration to use.",
59
- aliases: "-c",
60
- banner: "PATH"
63
+ desc: 'Path to Berkshelf configuration to use.',
64
+ aliases: '-c',
65
+ banner: 'PATH'
61
66
  class_option :format,
62
67
  type: :string,
63
- default: "human",
64
- desc: "Output format to use.",
65
- aliases: "-F",
66
- banner: "FORMAT"
68
+ default: 'human',
69
+ desc: 'Output format to use.',
70
+ aliases: '-F',
71
+ banner: 'FORMAT'
67
72
  class_option :quiet,
68
73
  type: :boolean,
69
- desc: "Silence all informational output.",
70
- aliases: "-q",
74
+ desc: 'Silence all informational output.',
75
+ aliases: '-q',
71
76
  default: false
72
77
  class_option :debug,
73
78
  type: :boolean,
74
- desc: "Output debug information",
75
- aliases: "-d",
79
+ desc: 'Output debug information',
80
+ aliases: '-d',
76
81
  default: false
77
82
 
78
83
  method_option :force,
79
84
  type: :boolean,
80
85
  default: false,
81
- desc: "create a new configuration file even if one already exists."
86
+ desc: 'create a new configuration file even if one already exists.'
82
87
  method_option :path,
83
88
  type: :string,
84
89
  default: Berkshelf::Config.path,
85
90
  desc: 'The path to save the configuration file'
86
- desc "configure", "Create a new configuration file to customize Berkshelf's behavior"
91
+ desc 'configure', 'Create a new Berkshelf configuration file'
87
92
  def configure
88
93
  path = File.expand_path(options[:path])
89
94
 
90
95
  if File.exist?(path) && !options[:force]
91
- raise Berkshelf::ConfigExists, "A configuration file already exists. Re-run with the --force flag if you wish to overwrite it."
96
+ raise Berkshelf::ConfigExists, 'A configuration file already exists. Re-run with the --force flag if you wish to overwrite it.'
92
97
  end
93
98
 
94
99
  @config = Berkshelf::Config.new(path)
95
100
 
96
101
  [
97
- "chef.chef_server_url",
98
- "chef.node_name",
99
- "chef.client_key",
100
- "chef.validation_client_name",
101
- "chef.validation_key_path",
102
- "vagrant.vm.box",
103
- "vagrant.vm.box_url",
102
+ 'chef.chef_server_url',
103
+ 'chef.node_name',
104
+ 'chef.client_key',
105
+ 'chef.validation_client_name',
106
+ 'chef.validation_key_path',
107
+ 'vagrant.vm.box',
108
+ 'vagrant.vm.box_url',
104
109
  ].each do |attribute|
105
110
  default = @config.get_attribute(attribute)
106
111
 
@@ -124,41 +129,26 @@ module Berkshelf
124
129
  Berkshelf.formatter.msg "Config written to: '#{path}'"
125
130
  end
126
131
 
127
- desc "open NAME", "Opens the source directory of an installed cookbook"
128
- def open(name)
129
- editor = [ENV['BERKSHELF_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
130
- raise ArgumentError, "To open a cookbook, set $EDITOR or $BERKSHELF_EDITOR" unless editor
131
-
132
- cookbook = Berkshelf.cookbook_store.cookbooks(name).last
133
- raise CookbookNotFound, "Cookbook '#{name}' not found in any of the sources!" unless cookbook
134
-
135
- Dir.chdir(cookbook.path) do
136
- command = "#{editor} #{cookbook.path}"
137
- success = system(command)
138
- raise CommandUnsuccessful, "Could not run `#{command}`" unless success
139
- end
140
- end
141
-
142
132
  method_option :except,
143
133
  type: :array,
144
- desc: "Exclude cookbooks that are in these groups.",
145
- aliases: "-e"
134
+ desc: 'Exclude cookbooks that are in these groups.',
135
+ aliases: '-e'
146
136
  method_option :only,
147
137
  type: :array,
148
- desc: "Only cookbooks that are in these groups.",
149
- aliases: "-o"
138
+ desc: 'Only cookbooks that are in these groups.',
139
+ aliases: '-o'
150
140
  method_option :berksfile,
151
141
  type: :string,
152
142
  default: Berkshelf::DEFAULT_FILENAME,
153
- desc: "Path to a Berksfile to operate off of.",
154
- aliases: "-b",
155
- banner: "PATH"
143
+ desc: 'Path to a Berksfile to operate off of.',
144
+ aliases: '-b',
145
+ banner: 'PATH'
156
146
  method_option :path,
157
147
  type: :string,
158
- desc: "Path to install cookbooks to (i.e. vendor/cookbooks).",
159
- aliases: "-p",
160
- banner: "PATH"
161
- desc "install", "Install the Cookbooks specified by a Berksfile or a Berksfile.lock"
148
+ desc: 'Path to install cookbooks to (i.e. vendor/cookbooks).',
149
+ aliases: '-p',
150
+ banner: 'PATH'
151
+ desc 'install', 'Install the cookbooks specified in the Berksfile'
162
152
  def install
163
153
  berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
164
154
  berksfile.install(options)
@@ -167,18 +157,18 @@ module Berkshelf
167
157
  method_option :berksfile,
168
158
  type: :string,
169
159
  default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
170
- desc: "Path to a Berksfile to operate off of.",
171
- aliases: "-b",
172
- banner: "PATH"
160
+ desc: 'Path to a Berksfile to operate off of.',
161
+ aliases: '-b',
162
+ banner: 'PATH'
173
163
  method_option :except,
174
164
  type: :array,
175
- desc: "Exclude cookbooks that are in these groups.",
176
- aliases: "-e"
165
+ desc: 'Exclude cookbooks that are in these groups.',
166
+ aliases: '-e'
177
167
  method_option :only,
178
168
  type: :array,
179
- desc: "Only cookbooks that are in these groups.",
180
- aliases: "-o"
181
- desc "update [COOKBOOKS]", "Update all Cookbooks and their dependencies specified by a Berksfile to their latest versions"
169
+ desc: 'Only cookbooks that are in these groups.',
170
+ aliases: '-o'
171
+ desc 'update [COOKBOOKS]', 'Update the cookbooks (and dependencies) specified in the Berksfile'
182
172
  def update(*cookbook_names)
183
173
  berksfile = Berksfile.from_file(options[:berksfile])
184
174
 
@@ -192,44 +182,44 @@ module Berkshelf
192
182
  method_option :berksfile,
193
183
  type: :string,
194
184
  default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
195
- desc: "Path to a Berksfile to operate off of.",
196
- aliases: "-b",
197
- banner: "PATH"
185
+ desc: 'Path to a Berksfile to operate off of.',
186
+ aliases: '-b',
187
+ banner: 'PATH'
198
188
  method_option :except,
199
189
  type: :array,
200
- desc: "Exclude cookbooks that are in these groups.",
201
- aliases: "-e"
190
+ desc: 'Exclude cookbooks that are in these groups.',
191
+ aliases: '-e'
202
192
  method_option :only,
203
193
  type: :array,
204
- desc: "Only cookbooks that are in these groups.",
205
- aliases: "-o"
194
+ desc: 'Only cookbooks that are in these groups.',
195
+ aliases: '-o'
206
196
  method_option :no_freeze,
207
197
  type: :boolean,
208
198
  default: false,
209
- desc: "Do not freeze uploaded cookbook(s)."
199
+ desc: 'Do not freeze uploaded cookbook(s).'
210
200
  method_option :force,
211
201
  type: :boolean,
212
202
  default: false,
213
- desc: "Upload all cookbook(s) even if a frozen one exists on the Chef Server."
203
+ desc: 'Upload all cookbook(s) even if a frozen one exists on the Chef Server.'
214
204
  method_option :ssl_verify,
215
205
  type: :boolean,
216
206
  default: nil,
217
- desc: "Disable/Enable SSL verification when uploading cookbooks."
207
+ desc: 'Disable/Enable SSL verification when uploading cookbooks.'
218
208
  method_option :skip_syntax_check,
219
209
  type: :boolean,
220
210
  default: false,
221
- desc: "Skip Ruby syntax check when uploading cookbooks.",
222
- aliases: "-s"
211
+ desc: 'Skip Ruby syntax check when uploading cookbooks.',
212
+ aliases: '-s'
223
213
  method_option :skip_dependencies,
224
214
  type: :boolean,
225
- desc: "Skip uploading dependent cookbook(s).",
215
+ desc: 'Skip uploading dependent cookbook(s).',
226
216
  default: false,
227
- aliases: "-D"
217
+ aliases: '-D'
228
218
  method_option :halt_on_frozen,
229
219
  type: :boolean,
230
220
  default: false,
231
- desc: "Halt uploading and exit if the Chef Server has a frozen version of the cookbook(s)."
232
- desc "upload [COOKBOOKS]", "Upload cookbook(s) specified by a Berksfile to the configured Chef Server."
221
+ desc: 'Halt uploading and exit if the Chef Server has a frozen version of the cookbook(s).'
222
+ desc 'upload [COOKBOOKS]', 'Upload the cookbook specified in the Berksfile to the Chef Server'
233
223
  def upload(*cookbook_names)
234
224
  berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
235
225
 
@@ -243,14 +233,14 @@ module Berkshelf
243
233
  method_option :berksfile,
244
234
  type: :string,
245
235
  default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
246
- desc: "Path to a Berksfile to operate off of.",
247
- aliases: "-b",
248
- banner: "PATH"
236
+ desc: 'Path to a Berksfile to operate off of.',
237
+ aliases: '-b',
238
+ banner: 'PATH'
249
239
  method_option :ssl_verify,
250
240
  type: :boolean,
251
241
  default: nil,
252
- desc: "Disable/Enable SSL verification when locking cookbooks."
253
- desc "apply ENVIRONMENT", "Apply cookbook locks of your Berksfile.lock to the target Chef environment."
242
+ desc: 'Disable/Enable SSL verification when locking cookbooks.'
243
+ desc 'apply ENVIRONMENT', 'Apply the cookbook version locks from Berksfile.lock to a Chef environment'
254
244
  def apply(environment_name)
255
245
  berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
256
246
  lock_options = Hash[options].symbolize_keys
@@ -261,24 +251,24 @@ module Berkshelf
261
251
  method_option :berksfile,
262
252
  type: :string,
263
253
  default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
264
- desc: "Path to a Berksfile to operate off of.",
265
- aliases: "-b",
266
- banner: "PATH"
254
+ desc: 'Path to a Berksfile to operate off of.',
255
+ aliases: '-b',
256
+ banner: 'PATH'
267
257
  method_option :except,
268
258
  type: :array,
269
- desc: "Exclude cookbooks that are in these groups.",
270
- aliases: "-e"
259
+ desc: 'Exclude cookbooks that are in these groups.',
260
+ aliases: '-e'
271
261
  method_option :only,
272
262
  type: :array,
273
- desc: "Only cookbooks that are in these groups.",
274
- aliases: "-o"
275
- desc "outdated [COOKBOOKS]", "Show all outdated cookbooks (exclusively from the community site)"
263
+ desc: 'Only cookbooks that are in these groups.',
264
+ aliases: '-o'
265
+ desc 'outdated [COOKBOOKS]', 'Show outdated cookbooks (from the community site)'
276
266
  def outdated(*cookbook_names)
277
267
  berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
278
- Berkshelf.formatter.msg "Listing outdated cookbooks with newer versions available..."
279
- Berkshelf.formatter.msg "BETA: this feature will only pull differences from the community site and will"
280
- Berkshelf.formatter.msg "BETA: ignore all other sources you may have defined"
281
- Berkshelf.formatter.msg ""
268
+ Berkshelf.formatter.msg 'Listing outdated cookbooks with newer versions available...'
269
+ Berkshelf.formatter.msg 'BETA: this feature will only pull differences from the community site and will'
270
+ Berkshelf.formatter.msg 'BETA: ignore all other sources you may have defined'
271
+ Berkshelf.formatter.msg ''
282
272
 
283
273
  outdated_options = {
284
274
  cookbooks: cookbook_names
@@ -287,7 +277,7 @@ module Berkshelf
287
277
  outdated = berksfile.outdated(outdated_options)
288
278
 
289
279
  if outdated.empty?
290
- Berkshelf.formatter.msg "All cookbooks up to date"
280
+ Berkshelf.formatter.msg 'All cookbooks up to date'
291
281
  else
292
282
  outdated.each do |cookbook, latest_version|
293
283
  Berkshelf.formatter.msg "Cookbook '#{cookbook.name} (#{cookbook.version_constraint})' is outdated (#{latest_version})"
@@ -295,10 +285,10 @@ module Berkshelf
295
285
  end
296
286
  end
297
287
 
298
- desc "init [PATH]", "Prepare a local path to have its Cookbook dependencies managed by Berkshelf"
288
+ desc 'init [PATH]', 'Initialize Berkshelf in the given directory'
299
289
  def init(path = Dir.pwd)
300
- Berkshelf.formatter.deprecation "--git is now the default" if options[:git]
301
- Berkshelf.formatter.deprecation "--vagrant is now the default" if options[:vagrant]
290
+ Berkshelf.formatter.deprecation '--git is now the default' if options[:git]
291
+ Berkshelf.formatter.deprecation '--vagrant is now the default' if options[:vagrant]
302
292
 
303
293
  if File.chef_cookbook?(path)
304
294
  options[:chefignore] = true
@@ -307,152 +297,105 @@ module Berkshelf
307
297
 
308
298
  ::Berkshelf::InitGenerator.new([path], options).invoke_all
309
299
 
310
- ::Berkshelf.formatter.msg "Successfully initialized"
300
+ ::Berkshelf.formatter.msg 'Successfully initialized'
311
301
  end
312
- tasks["init"].options = Berkshelf::InitGenerator.class_options
313
302
 
314
303
  method_option :berksfile,
315
304
  type: :string,
316
- default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
317
- desc: "Path to a Berksfile to operate off of.",
318
- aliases: "-b",
319
- banner: "PATH"
320
- desc "list", "Show all of the cookbooks in the current Berkshelf"
305
+ default: Berkshelf::DEFAULT_FILENAME,
306
+ desc: 'Path to a Berksfile to operate off of.',
307
+ aliases: '-b',
308
+ banner: 'PATH'
309
+ desc 'list', 'List all cookbooks (and dependencies) specified in the Berksfile'
321
310
  def list
322
- berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
311
+ berksfile = Berksfile.from_file(options[:berksfile])
312
+ sources = Berkshelf.ui.mute { berksfile.resolve(berksfile.sources)[:solution] }.sort
323
313
 
324
- Berkshelf.formatter.msg "Cookbooks installed by your Berksfile:"
325
- Berkshelf.ui.mute { berksfile.resolve(berksfile.sources)[:solution] }.sort.each do |cookbook|
326
- Berkshelf.formatter.msg " * #{cookbook.cookbook_name} (#{cookbook.version})"
314
+ if sources.empty?
315
+ Berkshelf.formatter.msg 'There are no cookbooks installed by your Berksfile'
316
+ else
317
+ Berkshelf.formatter.msg 'Cookbooks installed by your Berksfile:'
318
+ print_list(sources)
327
319
  end
328
320
  end
329
321
 
330
322
  method_option :berksfile,
331
323
  type: :string,
332
- default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
324
+ default: Berkshelf::DEFAULT_FILENAME,
333
325
  desc: "Path to a Berksfile to operate off of.",
334
326
  aliases: "-b",
335
327
  banner: "PATH"
336
- desc "show COOKBOOK", "Display the source path on the local file system for the given cookbook"
328
+ desc "show [COOKBOOK]", "Display name, author, copyright, and dependency information about a cookbook"
337
329
  def show(name)
338
- berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
339
- source = berksfile.find(name)
330
+ berksfile = Berksfile.from_file(options[:berksfile])
340
331
 
341
332
  cookbook = Berkshelf.ui.mute {
342
- berksfile.resolve(source)[:solution].first
333
+ berksfile.resolve(berksfile.find(name))[:solution].first
343
334
  }
344
335
 
345
- raise CookbookNotFound, "Cookbook '#{name}' was not installed by your Berksfile" unless cookbook
346
- Berkshelf.formatter.msg(cookbook.path)
347
- end
336
+ raise CookbookNotFound, "Cookbook '#{name}' is not installed by your Berksfile" unless cookbook
348
337
 
349
- method_option :version,
350
- type: :string,
351
- desc: 'The version of the cookbook to display.',
352
- aliases: '-v'
353
- desc "info [COOKBOOK]", "Display name, author, copyright, and dependency information about a cookbook"
354
- def info(name)
355
- if options[:version]
356
- cookbook = Berkshelf.cookbook_store.cookbook(name, options[:version])
357
- else
358
- cookbook = Berkshelf.cookbook_store.cookbooks(name).sort_by(&:version).last
359
- end
360
-
361
- raise CookbookNotFound, "Cookbook '#{name}' was not installed by your Berksfile" if cookbook.nil?
362
- Berkshelf.formatter.msg(cookbook.pretty_print)
338
+ Berkshelf.formatter.show(cookbook)
363
339
  end
364
340
 
365
341
  method_option :berksfile,
366
342
  type: :string,
367
- default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
368
- desc: "Path to a Berksfile to operate off of.",
369
- aliases: "-b",
370
- banner: "PATH"
371
- desc "contingent COOKBOOK", "Display a list of cookbooks that depend on the given cookbook"
343
+ default: Berkshelf::DEFAULT_FILENAME,
344
+ desc: 'Path to a Berksfile to operate off of.',
345
+ aliases: '-b',
346
+ banner: 'PATH'
347
+ desc 'contingent COOKBOOK', 'List all cookbooks that depend on the given cookbook'
372
348
  def contingent(name)
373
- berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
349
+ berksfile = Berksfile.from_file(options[:berksfile])
374
350
 
375
- Berkshelf.formatter.msg "Cookbooks contingent upon #{name}:"
376
- sources = Berkshelf.ui.mute { berksfile.resolve(berksfile.sources)[:solution] }.sort.each do |cookbook|
377
- if cookbook.dependencies.include?(name)
378
- Berkshelf.formatter.msg " * #{cookbook.cookbook_name} (#{cookbook.version})"
379
- end
351
+ sources = Berkshelf.ui.mute { berksfile.resolve(berksfile.sources)[:solution] }.sort
352
+ dependencies = sources.select { |cookbook| cookbook.dependencies.include?(name) }
353
+
354
+ if dependencies.empty?
355
+ Berkshelf.formatter.msg "There are no cookbooks contingent upon '#{name}' defined in this Berksfile"
356
+ else
357
+ Berkshelf.formatter.msg "Cookbooks in this Berksfile contingent upon #{name}:"
358
+ print_list(dependencies)
380
359
  end
381
360
  end
382
361
 
383
362
  method_option :berksfile,
384
363
  type: :string,
385
364
  default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
386
- desc: "Path to a Berksfile to operate off of.",
387
- aliases: "-b",
388
- banner: "PATH"
365
+ desc: 'Path to a Berksfile to operate off of.',
366
+ aliases: '-b',
367
+ banner: 'PATH'
389
368
  method_option :output,
390
369
  type: :string,
391
370
  default: Dir.pwd,
392
- desc: "Path to output the tarball",
393
- aliases: "-o",
394
- banner: "PATH"
371
+ desc: 'Path to output the tarball',
372
+ aliases: '-o',
373
+ banner: 'PATH'
395
374
  method_option :skip_dependencies,
396
375
  type: :boolean,
397
- desc: "Skip packaging dependent cookbook(s).",
376
+ desc: 'Skip packaging dependent cookbook(s).',
398
377
  default: false
399
378
  method_option :ignore_chefignore,
400
379
  type: :boolean,
401
- desc: "Do not apply the chefignore to the packaged contents",
380
+ desc: 'Do not apply the chefignore to the packaged contents',
402
381
  default: false
403
- desc "package [COOKBOOK]", "Package this cookbook and all it's dependencies in a tarball"
382
+ desc 'package [COOKBOOK]', 'Package a cookbook (and dependencies) as a tarball'
404
383
  def package(name = nil)
405
384
  berksfile = Berkshelf::Berksfile.from_file(options[:berksfile])
406
385
  berksfile.package(name, options)
407
386
  end
408
387
 
409
- desc "version", "Display version and copyright information"
388
+ desc 'version', 'Display version and copyright information'
410
389
  def version
411
390
  Berkshelf.formatter.msg version_header
412
391
  Berkshelf.formatter.msg "\n"
413
392
  Berkshelf.formatter.msg license
414
393
  end
415
394
 
416
- method_option :foodcritic,
417
- type: :boolean,
418
- desc: "Creates a Thorfile with Foodcritic support to lint test your cookbook"
419
- method_option :chef_minitest,
420
- type: :boolean,
421
- desc: "Creates chef-minitest support files and directories, adds minitest-handler cookbook to run_list of Vagrantfile"
422
- method_option :scmversion,
423
- type: :boolean,
424
- desc: "Creates a Thorfile with SCMVersion support to manage versions for continuous integration"
425
- method_option :license,
426
- type: :string,
427
- desc: "License for cookbook (apachev2, gplv2, gplv3, mit, reserved)",
428
- aliases: "-L"
429
- method_option :maintainer,
430
- type: :string,
431
- desc: "Name of cookbook maintainer",
432
- aliases: "-m"
433
- method_option :maintainer_email,
434
- type: :string,
435
- desc: "Email address of cookbook maintainer",
436
- aliases: "-e"
437
- method_option :no_bundler,
438
- type: :boolean,
439
- desc: "Skips generation of a Gemfile and other Bundler specific support"
440
- method_option :vagrant,
441
- type: :boolean,
442
- hide: true
443
- method_option :skip_vagrant,
444
- type: :boolean,
445
- desc: "Skips adding a Vagrantfile and adding supporting gems to the Gemfile"
446
- method_option :git,
447
- type: :boolean,
448
- hide: true
449
- method_option :skip_git,
450
- type: :boolean,
451
- desc: "Skips adding a .gitignore and running git init in the cookbook directory"
452
- desc "cookbook NAME", "Create a skeleton for a new cookbook"
395
+ desc 'cookbook NAME', 'Create a skeleton for a new cookbook'
453
396
  def cookbook(name)
454
- Berkshelf.formatter.deprecation "--git is now the default" if options[:git]
455
- Berkshelf.formatter.deprecation "--vagrant is now the default" if options[:vagrant]
397
+ Berkshelf.formatter.deprecation '--git is now the default' if options[:git]
398
+ Berkshelf.formatter.deprecation '--vagrant is now the default' if options[:vagrant]
456
399
 
457
400
  unless Config.instance.valid?
458
401
  raise InvalidConfiguration.new(Config.instance.errors)
@@ -460,6 +403,7 @@ module Berkshelf
460
403
 
461
404
  ::Berkshelf::CookbookGenerator.new([File.join(Dir.pwd, name), name], options).invoke_all
462
405
  end
406
+ tasks['cookbook'].options = Berkshelf::CookbookGenerator.class_options
463
407
 
464
408
  private
465
409
 
@@ -470,10 +414,16 @@ module Berkshelf
470
414
  def license
471
415
  File.read(Berkshelf.root.join('LICENSE'))
472
416
  end
473
- end
474
- end
475
417
 
476
- Dir["#{File.dirname(__FILE__)}/cli_commands/*.rb"].sort.each do |path|
477
- require "berkshelf/cli_commands/#{File.basename(path, '.rb')}"
418
+ # Print a list of the given cookbooks. This is used by various
419
+ # methods like {list} and {contingent}.
420
+ #
421
+ # @param [Array<CachedCookbook>] cookbooks
422
+ #
423
+ def print_list(cookbooks)
424
+ Array(cookbooks).each do |cookbook|
425
+ Berkshelf.formatter.msg " * #{cookbook.cookbook_name} (#{cookbook.version})"
426
+ end
427
+ end
428
+ end
478
429
  end
479
-