berkshelf 5.2.0 → 8.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +19 -47
  3. data/Rakefile +14 -4
  4. data/berkshelf.gemspec +61 -40
  5. data/bin/berks +2 -2
  6. data/lib/berkshelf/api-client.rb +1 -0
  7. data/lib/berkshelf/api_client/chef_server_connection.rb +29 -0
  8. data/lib/berkshelf/api_client/connection.rb +57 -0
  9. data/lib/berkshelf/api_client/errors.rb +10 -0
  10. data/lib/berkshelf/api_client/remote_cookbook.rb +56 -0
  11. data/lib/berkshelf/api_client/version.rb +5 -0
  12. data/lib/berkshelf/api_client.rb +24 -0
  13. data/lib/berkshelf/berksfile.rb +149 -122
  14. data/lib/berkshelf/cached_cookbook.rb +127 -24
  15. data/lib/berkshelf/chef_config_compat.rb +51 -0
  16. data/lib/berkshelf/chef_repo_universe.rb +47 -0
  17. data/lib/berkshelf/cli.rb +143 -174
  18. data/lib/berkshelf/commands/shelf.rb +20 -19
  19. data/lib/berkshelf/community_rest.rb +59 -94
  20. data/lib/berkshelf/config.rb +97 -127
  21. data/lib/berkshelf/cookbook_store.rb +7 -6
  22. data/lib/berkshelf/core_ext/file.rb +1 -1
  23. data/lib/berkshelf/core_ext/file_utils.rb +4 -4
  24. data/lib/berkshelf/core_ext.rb +1 -1
  25. data/lib/berkshelf/dependency.rb +25 -32
  26. data/lib/berkshelf/downloader.rb +66 -39
  27. data/lib/berkshelf/errors.rb +23 -17
  28. data/lib/berkshelf/file_syncer.rb +24 -47
  29. data/lib/berkshelf/formatters/human.rb +7 -5
  30. data/lib/berkshelf/formatters/json.rb +6 -6
  31. data/lib/berkshelf/installer.rb +120 -111
  32. data/lib/berkshelf/location.rb +14 -14
  33. data/lib/berkshelf/locations/base.rb +1 -1
  34. data/lib/berkshelf/locations/git.rb +16 -24
  35. data/lib/berkshelf/locations/github.rb +2 -2
  36. data/lib/berkshelf/locations/path.rb +2 -2
  37. data/lib/berkshelf/lockfile.rb +326 -328
  38. data/lib/berkshelf/logger.rb +64 -1
  39. data/lib/berkshelf/mixin/git.rb +6 -5
  40. data/lib/berkshelf/packager.rb +44 -10
  41. data/lib/berkshelf/resolver/graph.rb +1 -1
  42. data/lib/berkshelf/resolver.rb +4 -4
  43. data/lib/berkshelf/ridley_compat.rb +109 -0
  44. data/lib/berkshelf/shell.rb +2 -1
  45. data/lib/berkshelf/shell_out.rb +18 -0
  46. data/lib/berkshelf/source.rb +77 -33
  47. data/lib/berkshelf/source_uri.rb +4 -4
  48. data/lib/berkshelf/ssl_policies.rb +38 -0
  49. data/lib/berkshelf/thor.rb +1 -1
  50. data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
  51. data/lib/berkshelf/thor_ext.rb +1 -1
  52. data/lib/berkshelf/uploader.rb +106 -70
  53. data/lib/berkshelf/validator.rb +13 -5
  54. data/lib/berkshelf/version.rb +1 -1
  55. data/lib/berkshelf/visualizer.rb +16 -11
  56. data/lib/berkshelf.rb +106 -81
  57. data/spec/config/knife.rb +4 -4
  58. data/spec/data/trusted_certs/example.crt +22 -0
  59. data/spec/fixtures/Berksfile +3 -3
  60. data/spec/fixtures/complex-cookbook-path/cookbooks/app/metadata.rb +2 -0
  61. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins/metadata.rb +2 -0
  62. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins-config/metadata.rb +4 -0
  63. data/spec/fixtures/cookbook-path/jenkins-config/metadata.rb +3 -3
  64. data/spec/fixtures/cookbook-path-uploader/apt-2.3.6/metadata.rb +2 -0
  65. data/spec/fixtures/cookbook-path-uploader/build-essential-1.4.2/metadata.rb +2 -0
  66. data/spec/fixtures/cookbook-path-uploader/jenkins-2.0.3/metadata.rb +5 -0
  67. data/spec/fixtures/cookbook-path-uploader/jenkins-config-0.1.0/metadata.rb +4 -0
  68. data/spec/fixtures/cookbook-path-uploader/runit-1.5.8/metadata.rb +5 -0
  69. data/spec/fixtures/cookbook-path-uploader/yum-3.0.6/metadata.rb +2 -0
  70. data/spec/fixtures/cookbook-path-uploader/yum-epel-0.2.0/metadata.rb +3 -0
  71. data/spec/fixtures/cookbook-store/jenkins-2.0.3/metadata.rb +5 -5
  72. data/spec/fixtures/cookbook-store/jenkins-2.0.4/metadata.rb +4 -4
  73. data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -3
  74. data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +3 -3
  75. data/spec/spec_helper.rb +56 -64
  76. data/spec/support/chef_api.rb +15 -16
  77. data/spec/support/chef_server.rb +71 -69
  78. data/spec/support/git.rb +59 -58
  79. data/spec/support/kitchen.rb +0 -14
  80. data/spec/support/matchers/file_system_matchers.rb +4 -5
  81. data/spec/support/matchers/filepath_matchers.rb +2 -2
  82. data/spec/support/path_helpers.rb +17 -17
  83. data/spec/support/shared_examples/formatter.rb +1 -1
  84. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/attributes/default.rb +0 -0
  85. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/files/default/file.h +0 -0
  86. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/metadata.rb +2 -0
  87. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/recipes/default.rb +0 -0
  88. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/templates/default/template.erb +0 -0
  89. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/attributes/default.rb +0 -0
  90. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/files/default/file.h +0 -0
  91. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/metadata.rb +2 -0
  92. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/recipes/default.rb +0 -0
  93. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/templates/default/template.erb +0 -0
  94. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/attributes/default.rb +0 -0
  95. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/files/default/file.h +0 -0
  96. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/metadata.rb +2 -0
  97. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/recipes/default.rb +0 -0
  98. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/templates/default/template.erb +0 -0
  99. data/spec/unit/berkshelf/berksfile_spec.rb +84 -105
  100. data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
  101. data/spec/unit/berkshelf/berkshelf/api_client/connection_spec.rb +157 -0
  102. data/spec/unit/berkshelf/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
  103. data/spec/unit/berkshelf/berkshelf/api_client_spec.rb +9 -0
  104. data/spec/unit/berkshelf/cached_cookbook_spec.rb +45 -47
  105. data/spec/unit/berkshelf/chef_repo_universe_spec.rb +37 -0
  106. data/spec/unit/berkshelf/cli_spec.rb +7 -8
  107. data/spec/unit/berkshelf/community_rest_spec.rb +82 -90
  108. data/spec/unit/berkshelf/config_spec.rb +51 -22
  109. data/spec/unit/berkshelf/cookbook_store_spec.rb +41 -41
  110. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +7 -8
  111. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +1 -1
  112. data/spec/unit/berkshelf/dependency_spec.rb +48 -48
  113. data/spec/unit/berkshelf/downloader_spec.rb +191 -34
  114. data/spec/unit/berkshelf/errors_spec.rb +3 -3
  115. data/spec/unit/berkshelf/file_syncer_spec.rb +87 -87
  116. data/spec/unit/berkshelf/formatters/base_spec.rb +23 -23
  117. data/spec/unit/berkshelf/formatters/human_spec.rb +2 -2
  118. data/spec/unit/berkshelf/formatters/json_spec.rb +2 -2
  119. data/spec/unit/berkshelf/formatters/null_spec.rb +3 -3
  120. data/spec/unit/berkshelf/installer_spec.rb +8 -8
  121. data/spec/unit/berkshelf/location_spec.rb +11 -11
  122. data/spec/unit/berkshelf/locations/base_spec.rb +35 -36
  123. data/spec/unit/berkshelf/locations/git_spec.rb +90 -93
  124. data/spec/unit/berkshelf/locations/path_spec.rb +40 -41
  125. data/spec/unit/berkshelf/lockfile_parser_spec.rb +71 -71
  126. data/spec/unit/berkshelf/lockfile_spec.rb +205 -211
  127. data/spec/unit/berkshelf/logger_spec.rb +3 -3
  128. data/spec/unit/berkshelf/mixin/logging_spec.rb +5 -5
  129. data/spec/unit/berkshelf/packager_spec.rb +2 -2
  130. data/spec/unit/berkshelf/resolver/graph_spec.rb +10 -8
  131. data/spec/unit/berkshelf/resolver_spec.rb +17 -17
  132. data/spec/unit/berkshelf/ridley_compat_spec.rb +16 -0
  133. data/spec/unit/berkshelf/shell_spec.rb +34 -34
  134. data/spec/unit/berkshelf/source_spec.rb +186 -20
  135. data/spec/unit/berkshelf/source_uri_spec.rb +1 -1
  136. data/spec/unit/berkshelf/ssl_policies_spec.rb +86 -0
  137. data/spec/unit/berkshelf/uploader_spec.rb +146 -64
  138. data/spec/unit/berkshelf/validator_spec.rb +23 -16
  139. data/spec/unit/berkshelf/visualizer_spec.rb +24 -15
  140. data/spec/unit/berkshelf_spec.rb +18 -18
  141. metadata +138 -289
  142. data/.gitignore +0 -29
  143. data/.travis.yml +0 -64
  144. data/CHANGELOG.legacy.md +0 -307
  145. data/CHANGELOG.md +0 -1358
  146. data/CONTRIBUTING.md +0 -64
  147. data/Gemfile.lock +0 -399
  148. data/Guardfile +0 -23
  149. data/PLUGINS.md +0 -25
  150. data/README.md +0 -70
  151. data/Thorfile +0 -61
  152. data/appveyor.yml +0 -31
  153. data/docs/berkshelf_for_newcomers.md +0 -65
  154. data/features/berksfile.feature +0 -46
  155. data/features/commands/apply.feature +0 -41
  156. data/features/commands/contingent.feature +0 -48
  157. data/features/commands/cookbook.feature +0 -35
  158. data/features/commands/info.feature +0 -99
  159. data/features/commands/init.feature +0 -27
  160. data/features/commands/install.feature +0 -636
  161. data/features/commands/list.feature +0 -78
  162. data/features/commands/outdated.feature +0 -130
  163. data/features/commands/package.feature +0 -17
  164. data/features/commands/search.feature +0 -17
  165. data/features/commands/shelf/list.feature +0 -32
  166. data/features/commands/shelf/show.feature +0 -143
  167. data/features/commands/shelf/uninstall.feature +0 -96
  168. data/features/commands/show.feature +0 -83
  169. data/features/commands/update.feature +0 -142
  170. data/features/commands/upload.feature +0 -426
  171. data/features/commands/vendor.feature +0 -111
  172. data/features/commands/verify.feature +0 -29
  173. data/features/commands/viz.feature +0 -66
  174. data/features/community_site.feature +0 -37
  175. data/features/config.feature +0 -111
  176. data/features/help.feature +0 -11
  177. data/features/json_formatter.feature +0 -161
  178. data/features/lifecycle.feature +0 -378
  179. data/features/lockfile.feature +0 -378
  180. data/features/step_definitions/berksfile_steps.rb +0 -39
  181. data/features/step_definitions/chef/config_steps.rb +0 -12
  182. data/features/step_definitions/chef_server_steps.rb +0 -60
  183. data/features/step_definitions/cli_steps.rb +0 -18
  184. data/features/step_definitions/config_steps.rb +0 -46
  185. data/features/step_definitions/environment_steps.rb +0 -7
  186. data/features/step_definitions/filesystem_steps.rb +0 -269
  187. data/features/step_definitions/gem_steps.rb +0 -13
  188. data/features/step_definitions/json_steps.rb +0 -23
  189. data/features/step_definitions/utility_steps.rb +0 -11
  190. data/features/support/aruba.rb +0 -12
  191. data/features/support/env.rb +0 -82
  192. data/generator_files/Berksfile.erb +0 -11
  193. data/generator_files/CHANGELOG.md.erb +0 -3
  194. data/generator_files/Gemfile.erb +0 -8
  195. data/generator_files/README.md.erb +0 -42
  196. data/generator_files/Thorfile.erb +0 -11
  197. data/generator_files/Vagrantfile.erb +0 -117
  198. data/generator_files/chefignore +0 -94
  199. data/generator_files/default_recipe.erb +0 -6
  200. data/generator_files/default_test.rb.erb +0 -11
  201. data/generator_files/gitignore.erb +0 -23
  202. data/generator_files/helpers.rb.erb +0 -7
  203. data/generator_files/licenses/apachev2.erb +0 -13
  204. data/generator_files/licenses/gplv2.erb +0 -15
  205. data/generator_files/licenses/gplv3.erb +0 -14
  206. data/generator_files/licenses/mit.erb +0 -20
  207. data/generator_files/licenses/reserved.erb +0 -3
  208. data/generator_files/metadata.rb.erb +0 -11
  209. data/lib/berkshelf/base_generator.rb +0 -43
  210. data/lib/berkshelf/commands/test_command.rb +0 -13
  211. data/lib/berkshelf/cookbook_generator.rb +0 -133
  212. data/lib/berkshelf/init_generator.rb +0 -195
  213. data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
  214. data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
  215. data/spec/unit/berkshelf/cookbook_generator_spec.rb +0 -110
  216. data/spec/unit/berkshelf/init_generator_spec.rb +0 -263
@@ -0,0 +1,51 @@
1
+ require "chef-config/config"
2
+ require "chef-config/workstation_config_loader"
3
+ require "socket" unless defined?(Socket) # FIXME: why?
4
+
5
+ module Berkshelf
6
+ class ChefConfigCompat
7
+ # Create a new Chef Config object.
8
+ #
9
+ # @param [#to_s] path
10
+ # the path to the configuration file
11
+ # @param [Hash] options
12
+ def initialize(path, options = {})
13
+ ChefConfig::WorkstationConfigLoader.new(path).load
14
+ ChefConfig::Config.merge!(options)
15
+ ChefConfig::Config.export_proxies # Set proxy settings as environment variables
16
+ ChefConfig::Config.init_openssl # setup openssl + fips mode
17
+ end
18
+
19
+ # Keep defaults that aren't in ChefConfig::Config
20
+ def cookbook_copyright(*args, &block)
21
+ ChefConfig::Config.cookbook_copyright(*args, &block) || "YOUR_NAME"
22
+ end
23
+
24
+ def cookbook_email(*args, &block)
25
+ ChefConfig::Config.cookbook_email(*args, &block) || "YOUR_EMAIL"
26
+ end
27
+
28
+ def cookbook_license(*args, &block)
29
+ ChefConfig::Config.cookbook_license(*args, &block) || "reserved"
30
+ end
31
+
32
+ # The configuration as a hash
33
+ def to_hash
34
+ ChefConfig::Config.save(true)
35
+ end
36
+
37
+ # Load from a file
38
+ def self.from_file(file)
39
+ new(file)
40
+ end
41
+
42
+ # Behave just like ChefConfig::Config in general
43
+ def method_missing(name, *args, &block)
44
+ ChefConfig::Config.send(name, *args, &block)
45
+ end
46
+
47
+ def respond_to_missing?(name)
48
+ ChefConfig::Config.respond_to?(name)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,47 @@
1
+ require_relative "api_client/remote_cookbook"
2
+ require_relative "cached_cookbook"
3
+
4
+ module Berkshelf
5
+ # Shim to look like a Berkshelf::APIClient but for a chef repo folder.
6
+ #
7
+ # @since 6.1
8
+ class ChefRepoUniverse
9
+ def initialize(uri, **options)
10
+ @uri = uri
11
+ @path = options[:path]
12
+ @options = options
13
+ end
14
+
15
+ def universe
16
+ Dir.entries(cookbooks_path).sort.each_with_object([]) do |entry, cookbooks|
17
+ next if entry[0] == "." # Skip hidden folders.
18
+
19
+ entry_path = "#{cookbooks_path}/#{entry}"
20
+ next unless File.directory?(entry_path) # Skip non-dirs.
21
+
22
+ cookbook = begin
23
+ Berkshelf::CachedCookbook.from_path(entry_path)
24
+ rescue IOError
25
+ next # It wasn't a cookbook.
26
+ end
27
+ cookbooks << Berkshelf::APIClient::RemoteCookbook.new(
28
+ cookbook.cookbook_name,
29
+ cookbook.version,
30
+ location_type: "file_store",
31
+ location_path: entry_path,
32
+ dependencies: cookbook.metadata.dependencies
33
+ )
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def cookbooks_path
40
+ if File.exist?("#{@path}/cookbooks")
41
+ "#{@path}/cookbooks"
42
+ else
43
+ @path
44
+ end
45
+ end
46
+ end
47
+ end
data/lib/berkshelf/cli.rb CHANGED
@@ -1,9 +1,6 @@
1
- require 'berkshelf'
2
- require_relative 'config'
3
- require_relative 'init_generator'
4
- require_relative 'cookbook_generator'
5
- require_relative 'commands/shelf'
6
- require_relative 'commands/test_command'
1
+ require_relative "../berkshelf"
2
+ require_relative "config"
3
+ require_relative "commands/shelf"
7
4
 
8
5
  module Berkshelf
9
6
  class Cli < Thor
@@ -19,22 +16,20 @@ module Berkshelf
19
16
  end
20
17
 
21
18
  def execute!
22
- begin
23
- $stdin = @stdin
24
- $stdout = @stdout
25
- $stderr = @stderr
26
-
27
- Berkshelf::Cli.start(@argv)
28
- @kernel.exit(0)
29
- rescue Berkshelf::BerkshelfError => e
30
- Berkshelf.ui.error e
31
- Berkshelf.ui.error "\t" + e.backtrace.join("\n\t") if ENV['BERKSHELF_DEBUG']
32
- @kernel.exit(e.status_code)
33
- rescue Ridley::Errors::RidleyError => e
34
- Berkshelf.ui.error "#{e.class} #{e}"
35
- Berkshelf.ui.error "\t" + e.backtrace.join("\n\t") if ENV['BERKSHELF_DEBUG']
36
- @kernel.exit(47)
37
- end
19
+ $stdin = @stdin
20
+ $stdout = @stdout
21
+ $stderr = @stderr
22
+
23
+ Berkshelf::Cli.start(@argv)
24
+ @kernel.exit(0)
25
+ rescue Berkshelf::BerkshelfError => e
26
+ Berkshelf.ui.error e
27
+ Berkshelf.ui.error "\t" + e.backtrace.join("\n\t") if ENV["BERKSHELF_DEBUG"]
28
+ @kernel.exit(e.status_code)
29
+ rescue => e
30
+ Berkshelf.ui.error "#{e.class} #{e}"
31
+ Berkshelf.ui.error "\t" + e.backtrace.join("\n\t") if ENV["BERKSHELF_DEBUG"]
32
+ @kernel.exit(47)
38
33
  end
39
34
  end
40
35
 
@@ -43,14 +38,14 @@ module Berkshelf
43
38
  if given_args.length > 1 && !(given_args & Thor::HELP_MAPPINGS).empty?
44
39
  command = given_args.first
45
40
 
46
- if self.subcommands.include?(command)
47
- super(meth, [command, 'help'].compact, nil, config)
41
+ if subcommands.include?(command)
42
+ super(meth, [command, "help"].compact, nil, config)
48
43
  else
49
- super(meth, ['help', command].compact, nil, config)
44
+ super(meth, ["help", command].compact, nil, config)
50
45
  end
51
46
  else
52
47
  super
53
- Berkshelf.formatter.cleanup_hook unless config[:current_command].name == 'help'
48
+ Berkshelf.formatter.cleanup_hook unless config[:current_command].name == "help"
54
49
  end
55
50
  end
56
51
  end
@@ -79,66 +74,59 @@ module Berkshelf
79
74
  @options = options.dup # unfreeze frozen options Hash from Thor
80
75
  end
81
76
 
82
- namespace 'berkshelf'
77
+ namespace "berkshelf"
83
78
 
84
- map 'in' => :install
85
- map 'up' => :upload
86
- map 'ud' => :update
87
- map 'ls' => :list
88
- map 'book' => :cookbook
89
- map ['ver', '-v', '--version'] => :version
79
+ map "in" => :install
80
+ map "up" => :upload
81
+ map "ud" => :update
82
+ map "ls" => :list
83
+ map "book" => :cookbook
84
+ map ["ver", "-v", "--version"] => :version
90
85
 
91
86
  default_task :install
92
87
 
93
88
  class_option :config,
94
89
  type: :string,
95
- desc: 'Path to Berkshelf configuration to use.',
96
- aliases: '-c',
97
- banner: 'PATH'
90
+ desc: "Path to Berkshelf configuration to use.",
91
+ aliases: "-c",
92
+ banner: "PATH"
98
93
  class_option :format,
99
94
  type: :string,
100
- default: 'human',
101
- desc: 'Output format to use.',
102
- aliases: '-F',
103
- banner: 'FORMAT'
95
+ default: "human",
96
+ desc: "Output format to use.",
97
+ aliases: "-F",
98
+ banner: "FORMAT"
104
99
  class_option :quiet,
105
100
  type: :boolean,
106
- desc: 'Silence all informational output.',
107
- aliases: '-q',
101
+ desc: "Silence all informational output.",
102
+ aliases: "-q",
108
103
  default: false
109
104
  class_option :debug,
110
105
  type: :boolean,
111
- desc: 'Output debug information',
112
- aliases: '-d',
106
+ desc: "Output debug information",
107
+ aliases: "-d",
113
108
  default: false
114
109
 
115
110
  method_option :except,
116
111
  type: :array,
117
- desc: 'Exclude cookbooks that are in these groups.',
118
- aliases: '-e'
112
+ desc: "Exclude cookbooks that are in these groups.",
113
+ aliases: "-e"
119
114
  method_option :only,
120
115
  type: :array,
121
- desc: 'Only cookbooks that are in these groups.',
122
- aliases: '-o'
116
+ desc: "Only cookbooks that are in these groups.",
117
+ aliases: "-o"
123
118
  method_option :berksfile,
124
119
  type: :string,
125
120
  default: nil,
126
- desc: 'Path to a Berksfile to operate off of.',
127
- aliases: '-b',
128
- banner: 'PATH'
121
+ desc: "Path to a Berksfile to operate off of.",
122
+ aliases: "-b",
123
+ banner: "PATH"
129
124
  method_option :path,
130
125
  type: :string,
131
- aliases: '-p',
126
+ aliases: "-p",
132
127
  hide: true
133
- desc 'install', 'Install the cookbooks specified in the Berksfile'
128
+ desc "install", "Install the cookbooks specified in the Berksfile"
134
129
  def install
135
- if options[:path]
136
- # TODO: Remove in Berkshelf 4.0
137
- Berkshelf.formatter.deprecation "`berks install --path [PATH]` has been replaced by `berks vendor`."
138
- Berkshelf.formatter.deprecation "Re-run your command as `berks vendor [PATH]` or see `berks help vendor`."
139
- exit(1)
140
- end
141
-
142
130
  berksfile = Berksfile.from_options(options)
143
131
  berksfile.install
144
132
  end
@@ -146,18 +134,18 @@ module Berkshelf
146
134
  method_option :berksfile,
147
135
  type: :string,
148
136
  default: nil,
149
- desc: 'Path to a Berksfile to operate off of.',
150
- aliases: '-b',
151
- banner: 'PATH'
137
+ desc: "Path to a Berksfile to operate off of.",
138
+ aliases: "-b",
139
+ banner: "PATH"
152
140
  method_option :except,
153
141
  type: :array,
154
- desc: 'Exclude cookbooks that are in these groups.',
155
- aliases: '-e'
142
+ desc: "Exclude cookbooks that are in these groups.",
143
+ aliases: "-e"
156
144
  method_option :only,
157
145
  type: :array,
158
- desc: 'Only cookbooks that are in these groups.',
159
- aliases: '-o'
160
- desc 'update [COOKBOOKS]', 'Update the cookbooks (and dependencies) specified in the Berksfile'
146
+ desc: "Only cookbooks that are in these groups.",
147
+ aliases: "-o"
148
+ desc "update [COOKBOOKS]", "Update the cookbooks (and dependencies) specified in the Berksfile"
161
149
  def update(*cookbook_names)
162
150
  berksfile = Berksfile.from_options(options)
163
151
  berksfile.update(*cookbook_names)
@@ -166,70 +154,69 @@ module Berkshelf
166
154
  method_option :berksfile,
167
155
  type: :string,
168
156
  default: nil,
169
- desc: 'Path to a Berksfile to operate off of.',
170
- aliases: '-b',
171
- banner: 'PATH'
157
+ desc: "Path to a Berksfile to operate off of.",
158
+ aliases: "-b",
159
+ banner: "PATH"
172
160
  method_option :except,
173
161
  type: :array,
174
- desc: 'Exclude cookbooks that are in these groups.',
175
- aliases: '-e'
162
+ desc: "Exclude cookbooks that are in these groups.",
163
+ aliases: "-e"
176
164
  method_option :only,
177
165
  type: :array,
178
- desc: 'Only cookbooks that are in these groups.',
179
- aliases: '-o'
166
+ desc: "Only cookbooks that are in these groups.",
167
+ aliases: "-o"
180
168
  method_option :no_freeze,
181
169
  type: :boolean,
182
170
  default: false,
183
- desc: 'Do not freeze uploaded cookbook(s).'
171
+ desc: "Do not freeze uploaded cookbook(s)."
184
172
  method_option :force,
185
173
  type: :boolean,
186
174
  default: false,
187
- desc: 'Upload all cookbooks even if a frozen one exists on the Chef Server.'
175
+ desc: "Upload all cookbooks even if a frozen one exists on the Chef Server."
188
176
  method_option :ssl_verify,
189
177
  type: :boolean,
190
178
  default: nil,
191
- desc: 'Disable/Enable SSL verification when uploading cookbooks.'
179
+ desc: "Disable/Enable SSL verification when uploading cookbooks."
192
180
  method_option :skip_syntax_check,
193
181
  type: :boolean,
194
182
  default: false,
195
- desc: 'Skip Ruby syntax check when uploading cookbooks.',
196
- aliases: '-s'
183
+ desc: "Skip Ruby syntax check when uploading cookbooks.",
184
+ aliases: "-s"
197
185
  method_option :halt_on_frozen,
198
186
  type: :boolean,
199
187
  default: false,
200
- desc: 'Exit with a non zero exit code if the Chef Server already has the version of the cookbook(s).'
201
- desc 'upload [COOKBOOKS]', 'Upload the cookbook specified in the Berksfile to the Chef Server'
188
+ desc: "Exit with a non zero exit code if the Chef Server already has the version of the cookbook(s)."
189
+ desc "upload [COOKBOOKS]", "Upload the cookbook specified in the Berksfile to the Chef Server"
202
190
  def upload(*names)
203
191
  berksfile = Berksfile.from_options(options)
204
192
 
205
193
  options[:freeze] = !options[:no_freeze]
206
194
  options[:validate] = false if options[:skip_syntax_check]
207
-
208
- berksfile.upload(names, options.symbolize_keys)
195
+ berksfile.upload(names, options.each_with_object({}) { |(k, v), m| m[k.to_sym] = v })
209
196
  end
210
197
 
211
198
  method_option :envfile,
212
199
  type: :string,
213
- desc: 'Path to a JSON environment file to update.',
214
- aliases: '-f'
200
+ desc: "Path to a JSON environment file to update.",
201
+ aliases: "-f"
215
202
  method_option :lockfile,
216
203
  type: :string,
217
204
  default: Berkshelf::Lockfile::DEFAULT_FILENAME,
218
- desc: 'Path to a Berksfile.lock to operate off of.',
219
- aliases: '-b',
220
- banner: 'PATH'
205
+ desc: "Path to a Berksfile.lock to operate off of.",
206
+ aliases: "-b",
207
+ banner: "PATH"
221
208
  method_option :ssl_verify,
222
209
  type: :boolean,
223
210
  default: nil,
224
- desc: 'Disable/Enable SSL verification when locking cookbooks.'
225
- desc 'apply ENVIRONMENT', 'Apply version locks from Berksfile.lock to a Chef environment'
211
+ desc: "Disable/Enable SSL verification when locking cookbooks."
212
+ desc "apply ENVIRONMENT", "Apply version locks from Berksfile.lock to a Chef environment"
226
213
  def apply(environment_name)
227
214
  unless File.exist?(options[:lockfile])
228
215
  raise LockfileNotFound, "No lockfile found at #{options[:lockfile]}"
229
216
  end
230
217
 
231
218
  lockfile = Lockfile.from_file(options[:lockfile])
232
- lock_options = Hash[options].symbolize_keys
219
+ lock_options = Hash[options].each_with_object({}) { |(k, v), m| m[k.to_sym] = v }
233
220
 
234
221
  lockfile.apply(environment_name, lock_options)
235
222
  end
@@ -237,66 +224,56 @@ module Berkshelf
237
224
  method_option :berksfile,
238
225
  type: :string,
239
226
  default: nil,
240
- desc: 'Path to a Berksfile to operate off of.',
241
- aliases: '-b',
242
- banner: 'PATH'
227
+ desc: "Path to a Berksfile to operate off of.",
228
+ aliases: "-b",
229
+ banner: "PATH"
243
230
  method_option :except,
244
231
  type: :array,
245
- desc: 'Exclude cookbooks that are in these groups.',
246
- aliases: '-e'
232
+ desc: "Exclude cookbooks that are in these groups.",
233
+ aliases: "-e"
247
234
  method_option :only,
248
235
  type: :array,
249
- desc: 'Only cookbooks that are in these groups.',
250
- aliases: '-o'
251
- desc 'outdated [COOKBOOKS]', 'List dependencies that have new versions available that satisfy their constraints'
236
+ desc: "Only cookbooks that are in these groups.",
237
+ aliases: "-o"
238
+ method_option :all,
239
+ type: :boolean,
240
+ desc: "Include cookbooks that don't satisfy the version constraints.",
241
+ aliases: "-a",
242
+ default: false
243
+ desc "outdated [COOKBOOKS]", "List dependencies that have new versions available that satisfy their constraints"
252
244
  def outdated(*names)
253
245
  berksfile = Berksfile.from_options(options)
254
- outdated = berksfile.outdated(*names)
246
+ outdated = berksfile.outdated(*names, include_non_satisfying: options[:all])
255
247
  Berkshelf.formatter.outdated(outdated)
256
248
  end
257
249
 
258
250
  method_option :source,
259
251
  type: :string,
260
252
  default: Berksfile::DEFAULT_API_URL,
261
- desc: 'URL to search for sources',
262
- banner: 'URL'
263
- desc 'search NAME', 'Search the remote source for cookbooks matching the partial name'
253
+ desc: "URL to search for sources",
254
+ banner: "URL"
255
+ desc "search NAME", "Search the remote source for cookbooks matching the partial name"
264
256
  def search(name)
265
- source = Source.new(options[:source])
257
+ source = Source.new(nil, options[:source])
266
258
  cookbooks = source.search(name)
267
259
  Berkshelf.formatter.search(cookbooks)
268
260
  end
269
261
 
270
- desc 'init [PATH]', 'Initialize Berkshelf in the given directory'
271
- def init(path = '.')
272
- Berkshelf.formatter.deprecation <<EOF
273
- This command is being deprecated in favor of `chef generate cookbook` and will soon return an error.
274
- Please use `chef generate cookbook` instead of this command.
275
- EOF
276
- Berkshelf.formatter.deprecation '--git is now the default' if options[:git]
277
- Berkshelf.formatter.deprecation '--vagrant is now the default' if options[:vagrant]
278
-
279
- Berkshelf::InitGenerator.new([path], options).invoke_all
280
-
281
- Berkshelf.formatter.msg 'Successfully initialized'
282
- end
283
- tasks['init'].options = Berkshelf::InitGenerator.class_options
284
-
285
262
  method_option :berksfile,
286
263
  type: :string,
287
264
  default: nil,
288
- desc: 'Path to a Berksfile to operate off of.',
289
- aliases: '-b',
290
- banner: 'PATH'
265
+ desc: "Path to a Berksfile to operate off of.",
266
+ aliases: "-b",
267
+ banner: "PATH"
291
268
  method_option :except,
292
269
  type: :array,
293
- desc: 'Exclude cookbooks that are in these groups.',
294
- aliases: '-e'
270
+ desc: "Exclude cookbooks that are in these groups.",
271
+ aliases: "-e"
295
272
  method_option :only,
296
273
  type: :array,
297
- desc: 'Only cookbooks that are in these groups.',
298
- aliases: '-o'
299
- desc 'list', 'List cookbooks and their dependencies specified by your Berksfile'
274
+ desc: "Only cookbooks that are in these groups.",
275
+ aliases: "-o"
276
+ desc "list", "List cookbooks and their dependencies specified by your Berksfile"
300
277
  def list
301
278
  berksfile = Berksfile.from_options(options)
302
279
  Berkshelf.formatter.list(berksfile.list)
@@ -331,10 +308,10 @@ EOF
331
308
  method_option :berksfile,
332
309
  type: :string,
333
310
  default: nil,
334
- desc: 'Path to a Berksfile to operate off of.',
335
- aliases: '-b',
336
- banner: 'PATH'
337
- desc 'contingent COOKBOOK', 'List all cookbooks that depend on the given cookbook in your Berksfile'
311
+ desc: "Path to a Berksfile to operate off of.",
312
+ aliases: "-b",
313
+ banner: "PATH"
314
+ desc "contingent COOKBOOK", "List all cookbooks that depend on the given cookbook in your Berksfile"
338
315
  def contingent(name)
339
316
  berksfile = Berksfile.from_options(options)
340
317
  dependencies = berksfile.cookbooks.select do |cookbook|
@@ -352,9 +329,9 @@ EOF
352
329
  method_option :berksfile,
353
330
  type: :string,
354
331
  default: nil,
355
- desc: 'Path to a Berksfile to operate off of.',
356
- aliases: '-b',
357
- banner: 'PATH'
332
+ desc: "Path to a Berksfile to operate off of.",
333
+ aliases: "-b",
334
+ banner: "PATH"
358
335
  method_option :except,
359
336
  type: :array,
360
337
  desc: "Exclude cookbooks that are in these groups.",
@@ -377,22 +354,22 @@ EOF
377
354
 
378
355
  method_option :except,
379
356
  type: :array,
380
- desc: 'Exclude cookbooks that are in these groups.',
381
- aliases: '-e'
357
+ desc: "Exclude cookbooks that are in these groups.",
358
+ aliases: "-e"
382
359
  method_option :delete,
383
360
  type: :boolean,
384
361
  desc: "Clean the target directory before vendoring",
385
362
  default: false
386
363
  method_option :only,
387
364
  type: :array,
388
- desc: 'Only cookbooks that are in these groups.',
389
- aliases: '-o'
365
+ desc: "Only cookbooks that are in these groups.",
366
+ aliases: "-o"
390
367
  method_option :berksfile,
391
368
  type: :string,
392
369
  default: nil,
393
- desc: 'Path to a Berksfile to operate off of.',
394
- aliases: '-b',
395
- banner: 'PATH'
370
+ desc: "Path to a Berksfile to operate off of.",
371
+ aliases: "-b",
372
+ banner: "PATH"
396
373
  desc "vendor [PATH]", "Vendor the cookbooks specified by the Berksfile into a directory"
397
374
  def vendor(path = File.join(Dir.pwd, "berks-cookbooks"))
398
375
  berksfile = Berkshelf::Berksfile.from_options(options)
@@ -412,53 +389,45 @@ EOF
412
389
  method_option :berksfile,
413
390
  type: :string,
414
391
  default: nil,
415
- desc: 'Path to a Berksfile to operate off of.',
416
- aliases: '-b',
417
- banner: 'PATH'
392
+ desc: "Path to a Berksfile to operate off of.",
393
+ aliases: "-b",
394
+ banner: "PATH"
418
395
  method_option :outfile,
419
396
  type: :string,
420
- default: 'graph.png',
421
- desc: 'The name of the output file',
422
- aliases: '-o',
423
- banner: 'NAME'
397
+ default: "graph.png",
398
+ desc: "The name of the output file",
399
+ aliases: "-o",
400
+ banner: "NAME"
401
+ method_option :outfile_format,
402
+ type: :string,
403
+ default: "png",
404
+ desc: "The format of the output file, either png or dot.",
405
+ aliases: "-f",
406
+ banner: "FORMAT"
424
407
  desc "viz", "Visualize the dependency graph"
425
408
  def viz
426
409
  berksfile = Berksfile.from_options(options)
427
- path = berksfile.viz(options[:outfile])
410
+ path = berksfile.viz(options[:outfile], options[:outfile_format])
428
411
 
429
412
  Berkshelf.ui.info(path)
430
413
  end
431
414
 
432
- desc 'version', 'Display version'
415
+ desc "version", "Display version"
433
416
  def version
434
417
  Berkshelf.formatter.version
435
418
  end
436
419
 
437
- desc 'cookbook NAME [PATH]', 'Create a skeleton for a new cookbook'
438
- def cookbook(name, path = nil)
439
- Berkshelf.formatter.deprecation <<EOF
440
- This command is being deprecated in favor of `chef generate cookbook` and will soon return an error.
441
- Please use `chef generate cookbook` instead of this command.
442
- EOF
443
- path = File.join(Dir.pwd, name) if path.nil?
444
- Berkshelf.formatter.deprecation '--git is now the default' if options[:git]
445
- Berkshelf.formatter.deprecation '--vagrant is now the default' if options[:vagrant]
446
-
447
- Berkshelf::CookbookGenerator.new([path, name], options).invoke_all
448
- end
449
- tasks['cookbook'].options = Berkshelf::CookbookGenerator.class_options
450
-
451
420
  private
452
421
 
453
- # Print a list of the given cookbooks. This is used by various
454
- # methods like {list} and {contingent}.
455
- #
456
- # @param [Array<CachedCookbook>] cookbooks
457
- #
458
- def print_list(cookbooks)
459
- Array(cookbooks).sort.each do |cookbook|
460
- Berkshelf.formatter.msg " * #{cookbook.cookbook_name} (#{cookbook.version})"
461
- end
422
+ # Print a list of the given cookbooks. This is used by various
423
+ # methods like {list} and {contingent}.
424
+ #
425
+ # @param [Array<CachedCookbook>] cookbooks
426
+ #
427
+ def print_list(cookbooks)
428
+ Array(cookbooks).sort.each do |cookbook|
429
+ Berkshelf.formatter.msg " * #{cookbook.cookbook_name} (#{cookbook.version})"
462
430
  end
431
+ end
463
432
  end
464
433
  end