chef-cli 3.1.0 → 4.0.1
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/Gemfile +2 -8
- data/lib/chef-cli/command/generator_commands/cookbook.rb +18 -1
- data/lib/chef-cli/command/generator_commands/generator_generator.rb +1 -1
- data/lib/chef-cli/completions/chef.fish.erb +4 -5
- data/lib/chef-cli/generator.rb +1 -1
- data/lib/chef-cli/helpers.rb +10 -7
- data/lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb +24 -19
- data/lib/chef-cli/skeletons/code_generator/templates/default/delivery-project.toml.erb +36 -0
- data/lib/chef-cli/skeletons/code_generator/templates/default/inspec_default_test.rb.erb +1 -1
- data/lib/chef-cli/skeletons/code_generator/templates/default/kitchen_dokken.yml.erb +1 -0
- data/lib/chef-cli/version.rb +1 -1
- data/spec/unit/command/generator_commands/cookbook_spec.rb +52 -1
- data/spec/unit/command/generator_commands/generator_generator_spec.rb +1 -1
- data/spec/unit/command/shell_init_spec.rb +10 -10
- data/spec/unit/helpers_spec.rb +111 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a10a665d45110e002c2e070387a8d91e0f6cdb365c8ed20b7f181739c0612e74
|
4
|
+
data.tar.gz: 8ee4a30784d2f1784a40d3be7bb5ef670970b6e9e55f922b1944d80253567ae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '019fa209b216d7719c8c53ce8df805bd973edeeb84a386d2fc1d0dcc08e5094953ed952e8d1e21a31d85053ab9b752e40160674139e6e0929433c8d26ab59896'
|
7
|
+
data.tar.gz: 4f147e219f59c6b9d1ddf864c20aed77bdd99dc4165c5035b823f084824f10772518ff9e30a95f110a5270d7fd5a9c2551f9ffc542c7e21bf20e000370083851
|
data/Gemfile
CHANGED
@@ -2,12 +2,6 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
group :docs do
|
6
|
-
gem "yard"
|
7
|
-
gem "redcarpet"
|
8
|
-
gem "github-markup"
|
9
|
-
end
|
10
|
-
|
11
5
|
group :test do
|
12
6
|
gem "rake"
|
13
7
|
gem "rspec", "~> 3.8"
|
@@ -15,17 +9,17 @@ group :test do
|
|
15
9
|
gem "rspec-mocks", "~> 3.8"
|
16
10
|
gem "cookstyle", "=7.7.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command
|
17
11
|
gem "chefstyle", "=1.6.2"
|
18
|
-
gem "test-kitchen", "
|
12
|
+
gem "test-kitchen", ">= 2.11.1"
|
19
13
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6")
|
20
14
|
gem "chef-zero", "~> 14"
|
21
15
|
gem "chef", "~> 15"
|
16
|
+
gem "chef-utils", "=16.6.14"
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
25
20
|
group :development do
|
26
21
|
gem "pry"
|
27
22
|
gem "pry-byebug"
|
28
|
-
gem "pry-stack_explorer", "~> 0.4.0"
|
29
23
|
gem "rb-readline"
|
30
24
|
end
|
31
25
|
|
@@ -55,6 +55,13 @@ module ChefCLI
|
|
55
55
|
boolean: true,
|
56
56
|
default: nil
|
57
57
|
|
58
|
+
option :specs,
|
59
|
+
short: "-s",
|
60
|
+
long: "--specs",
|
61
|
+
description: "Generate a cookbook with sample ChefSpec specs",
|
62
|
+
boolean: true,
|
63
|
+
default: nil
|
64
|
+
|
58
65
|
option :workflow,
|
59
66
|
short: "-w",
|
60
67
|
long: "--workflow",
|
@@ -81,6 +88,7 @@ module ChefCLI
|
|
81
88
|
@cookbook_name = nil
|
82
89
|
@policy_mode = true
|
83
90
|
@verbose = false
|
91
|
+
@specs = false
|
84
92
|
super
|
85
93
|
end
|
86
94
|
|
@@ -133,6 +141,7 @@ module ChefCLI
|
|
133
141
|
Generator.add_attr_to_context(:workflow_project_git_initialized, have_git? && !cookbook_path_in_git_repo?)
|
134
142
|
|
135
143
|
Generator.add_attr_to_context(:verbose, verbose?)
|
144
|
+
Generator.add_attr_to_context(:specs, specs?)
|
136
145
|
|
137
146
|
Generator.add_attr_to_context(:use_policyfile, policy_mode?)
|
138
147
|
Generator.add_attr_to_context(:pipeline, pipeline)
|
@@ -188,6 +197,10 @@ module ChefCLI
|
|
188
197
|
@verbose
|
189
198
|
end
|
190
199
|
|
200
|
+
def specs?
|
201
|
+
@specs
|
202
|
+
end
|
203
|
+
|
191
204
|
#
|
192
205
|
# Is there a .delivery/cli.toml in the current dir or any of the parent dirs
|
193
206
|
#
|
@@ -207,7 +220,7 @@ module ChefCLI
|
|
207
220
|
if !@cookbook_name_or_path
|
208
221
|
@params_valid = false
|
209
222
|
elsif File.basename(@cookbook_name_or_path).include?("-")
|
210
|
-
msg("Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/ctl_chef/#chef-generate-cookbook for more information.")
|
223
|
+
msg("Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook for more information.")
|
211
224
|
end
|
212
225
|
|
213
226
|
if config[:berks] && config[:policy]
|
@@ -223,6 +236,10 @@ module ChefCLI
|
|
223
236
|
@verbose = true
|
224
237
|
end
|
225
238
|
|
239
|
+
if config[:specs]
|
240
|
+
@specs = true
|
241
|
+
end
|
242
|
+
|
226
243
|
true
|
227
244
|
end
|
228
245
|
|
@@ -109,7 +109,7 @@ module ChefCLI
|
|
109
109
|
# @api private
|
110
110
|
def metadata_rb
|
111
111
|
<<~METADATA
|
112
|
-
name
|
112
|
+
name File.basename(File.dirname(__FILE__))
|
113
113
|
description 'Custom code generator cookbook for use with #{ChefCLI::Dist::PRODUCT}'
|
114
114
|
version '0.1.0'
|
115
115
|
|
@@ -1,10 +1,9 @@
|
|
1
|
+
|
1
2
|
# Fish Shell command-line completions for <%=ChefCLI::Dist::PRODUCT %>
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
test (count $cmd) -eq 1
|
6
|
-
end
|
4
|
+
# set a list of all the chef commands in the Ruby chef-cli
|
5
|
+
set -l chef_commands <%= commands.keys.join(' ') %>;
|
7
6
|
|
8
7
|
<% commands.each do |command, desc| -%>
|
9
|
-
complete -c chef -f -n
|
8
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a <%= command %> -d "<%= desc %>";
|
10
9
|
<% end -%>
|
data/lib/chef-cli/generator.rb
CHANGED
@@ -150,7 +150,7 @@ module ChefCLI
|
|
150
150
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
151
151
|
EOH
|
152
152
|
else
|
153
|
-
raise ArgumentError, "Invalid generator.license setting: #{license}. See available licenses at https://docs.chef.io/ctl_chef/#chef-generate-cookbook"
|
153
|
+
raise ArgumentError, "Invalid generator.license setting: #{license}. See available licenses at https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook"
|
154
154
|
end
|
155
155
|
if comment
|
156
156
|
# Ensure there's no trailing whitespace
|
data/lib/chef-cli/helpers.rb
CHANGED
@@ -87,7 +87,7 @@ module ChefCLI
|
|
87
87
|
# On Mac we place all of our symlinks under /usr/local/bin on other
|
88
88
|
# platforms they are under /usr/bin
|
89
89
|
def usr_bin_prefix
|
90
|
-
@usr_bin_prefix ||=
|
90
|
+
@usr_bin_prefix ||= macos? ? "/usr/local/bin" : "/usr/bin"
|
91
91
|
end
|
92
92
|
|
93
93
|
# Returns the full path to the given command under usr_bin_prefix
|
@@ -117,11 +117,11 @@ module ChefCLI
|
|
117
117
|
@omnibus_env ||=
|
118
118
|
begin
|
119
119
|
user_bin_dir = File.expand_path(File.join(Gem.user_dir, "bin"))
|
120
|
-
path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"] ]
|
120
|
+
path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ]
|
121
121
|
path << git_bin_dir if Dir.exist?(git_bin_dir)
|
122
122
|
path << git_windows_bin_dir if Dir.exist?(git_windows_bin_dir)
|
123
123
|
{
|
124
|
-
"PATH" => path.join(File::PATH_SEPARATOR),
|
124
|
+
"PATH" => path.flatten.uniq.join(File::PATH_SEPARATOR),
|
125
125
|
"GEM_ROOT" => Gem.default_dir,
|
126
126
|
"GEM_HOME" => Gem.user_dir,
|
127
127
|
"GEM_PATH" => Gem.path.join(File::PATH_SEPARATOR),
|
@@ -129,8 +129,6 @@ module ChefCLI
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
private
|
133
|
-
|
134
132
|
def omnibus_expand_path(*paths)
|
135
133
|
dir = File.expand_path(File.join(paths))
|
136
134
|
raise OmnibusInstallNotFound.new unless dir && File.directory?(dir)
|
@@ -138,6 +136,8 @@ module ChefCLI
|
|
138
136
|
dir
|
139
137
|
end
|
140
138
|
|
139
|
+
private
|
140
|
+
|
141
141
|
def expected_omnibus_root
|
142
142
|
File.expand_path(File.join(Gem.ruby, "..", "..", ".."))
|
143
143
|
end
|
@@ -166,8 +166,11 @@ module ChefCLI
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
-
# Returns true if we are on
|
170
|
-
|
169
|
+
# @return [Boolean] Returns true if we are on macOS. Otherwise false
|
170
|
+
#
|
171
|
+
# @api private
|
172
|
+
#
|
173
|
+
def macos?
|
171
174
|
!!(RUBY_PLATFORM =~ /darwin/)
|
172
175
|
end
|
173
176
|
end
|
@@ -92,24 +92,26 @@ template "#{cookbook_dir}/test/integration/default/default_test.rb" do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
# ChefSpec
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
|
100
|
-
if context.use_policyfile
|
101
|
-
source 'spec_helper_policyfile.rb'
|
102
|
-
else
|
103
|
-
source 'spec_helper.rb'
|
95
|
+
if context.specs
|
96
|
+
directory "#{cookbook_dir}/spec/unit/recipes" do
|
97
|
+
recursive true
|
104
98
|
end
|
105
99
|
|
106
|
-
|
107
|
-
|
100
|
+
cookbook_file "#{cookbook_dir}/spec/spec_helper.rb" do
|
101
|
+
if context.use_policyfile
|
102
|
+
source 'spec_helper_policyfile.rb'
|
103
|
+
else
|
104
|
+
source 'spec_helper.rb'
|
105
|
+
end
|
108
106
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
107
|
+
action :create_if_missing
|
108
|
+
end
|
109
|
+
|
110
|
+
template "#{cookbook_dir}/spec/unit/recipes/default_spec.rb" do
|
111
|
+
source 'recipe_spec.rb.erb'
|
112
|
+
helpers(ChefCLI::Generator::TemplateHelper)
|
113
|
+
action :create_if_missing
|
114
|
+
end
|
113
115
|
end
|
114
116
|
|
115
117
|
# Recipes
|
@@ -125,10 +127,13 @@ end
|
|
125
127
|
unless context.enable_workflow
|
126
128
|
directory "#{cookbook_dir}/.delivery"
|
127
129
|
|
128
|
-
#
|
129
|
-
|
130
|
-
|
131
|
-
|
130
|
+
template "#{cookbook_dir}/.delivery/project.toml" do
|
131
|
+
variables(
|
132
|
+
specs: context.specs
|
133
|
+
)
|
134
|
+
source 'delivery-project.toml.erb'
|
135
|
+
helpers(ChefCLI::Generator::TemplateHelper)
|
136
|
+
action :create_if_missing
|
132
137
|
end
|
133
138
|
end
|
134
139
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Delivery for Local Phases Execution
|
2
|
+
#
|
3
|
+
# This file allows you to execute test phases locally on a workstation or
|
4
|
+
# in a CI pipeline. The delivery-cli will read this file and execute the
|
5
|
+
# command(s) that are configured for each phase. You can customize them
|
6
|
+
# by just modifying the phase key on this file.
|
7
|
+
#
|
8
|
+
# By default these phases are configured for Cookbook Workflow only
|
9
|
+
#
|
10
|
+
|
11
|
+
[local_phases]
|
12
|
+
<% if @specs %>
|
13
|
+
unit = "chef exec rspec spec/"
|
14
|
+
<% else %>
|
15
|
+
unit = "echo skipping unit phase."
|
16
|
+
<% end %>
|
17
|
+
lint = "chef exec cookstyle"
|
18
|
+
# foodcritic has been deprecated in favor of cookstyle so we skip the syntax
|
19
|
+
# phase now.
|
20
|
+
syntax = "echo skipping syntax phase. Use lint phase instead."
|
21
|
+
provision = "chef exec kitchen create"
|
22
|
+
deploy = "chef exec kitchen converge"
|
23
|
+
smoke = "chef exec kitchen verify"
|
24
|
+
# The functional phase is optional, you can define it by uncommenting
|
25
|
+
# the line below and running the command: `delivery local functional`
|
26
|
+
# functional = ""
|
27
|
+
cleanup = "chef exec kitchen destroy"
|
28
|
+
|
29
|
+
# Remote project.toml file
|
30
|
+
#
|
31
|
+
# Instead of the local phases above, you may specify a remote URI location for
|
32
|
+
# the `project.toml` file. This is useful for teams that wish to centrally
|
33
|
+
# manage the behavior of the `delivery local` command across many different
|
34
|
+
# projects.
|
35
|
+
#
|
36
|
+
# remote_file = "https://url/project.toml"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# InSpec test for recipe <%= cookbook_name %>::<%= recipe_name %>
|
2
2
|
|
3
|
-
# The InSpec reference, with examples and extensive documentation, can be
|
3
|
+
# The Chef InSpec reference, with examples and extensive documentation, can be
|
4
4
|
# found at https://docs.chef.io/inspec/resources/
|
5
5
|
|
6
6
|
unless os.windows?
|
data/lib/chef-cli/version.rb
CHANGED
@@ -30,6 +30,24 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
30
30
|
let(:stderr_io) { StringIO.new }
|
31
31
|
|
32
32
|
let(:expected_cookbook_file_relpaths) do
|
33
|
+
%w{
|
34
|
+
.gitignore
|
35
|
+
kitchen.yml
|
36
|
+
test
|
37
|
+
test/integration
|
38
|
+
test/integration/default/default_test.rb
|
39
|
+
Policyfile.rb
|
40
|
+
chefignore
|
41
|
+
LICENSE
|
42
|
+
metadata.rb
|
43
|
+
README.md
|
44
|
+
CHANGELOG.md
|
45
|
+
recipes
|
46
|
+
recipes/default.rb
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
let(:expected_cookbook_file_relpaths_specs) do
|
33
51
|
%w{
|
34
52
|
.gitignore
|
35
53
|
kitchen.yml
|
@@ -58,6 +76,12 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
58
76
|
end
|
59
77
|
end
|
60
78
|
|
79
|
+
let(:expected_cookbook_files_specs) do
|
80
|
+
expected_cookbook_file_relpaths_specs.map do |relpath|
|
81
|
+
File.join(tempdir, "new_cookbook", relpath)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
61
85
|
let(:non_delivery_breadcrumb) do
|
62
86
|
<<~EOF
|
63
87
|
Your cookbook is ready. Type `cd new_cookbook` to enter it.
|
@@ -129,7 +153,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
129
153
|
|
130
154
|
it "warns if a hyphenated cookbook name is passed" do
|
131
155
|
expect(with_argv(%w{my-cookbook}).run).to eq(0)
|
132
|
-
message = "Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/ctl_chef/#chef-generate-cookbook for more information."
|
156
|
+
message = "Hyphens are discouraged in cookbook names as they may cause problems with custom resources. See https://docs.chef.io/workstation/ctl_chef/#chef-generate-cookbook for more information."
|
133
157
|
expect(stdout_io.string).to include(message)
|
134
158
|
end
|
135
159
|
|
@@ -150,9 +174,11 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
150
174
|
expect(generator_context.cookbook_name).to eq("new_cookbook")
|
151
175
|
expect(generator_context.recipe_name).to eq("default")
|
152
176
|
expect(generator_context.verbose).to be(false)
|
177
|
+
expect(generator_context.specs).to be(false)
|
153
178
|
end
|
154
179
|
|
155
180
|
it "creates a new cookbook" do
|
181
|
+
|
156
182
|
Dir.chdir(tempdir) do
|
157
183
|
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
158
184
|
expect(cookbook_generator.run).to eq(0)
|
@@ -398,6 +424,28 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
398
424
|
end
|
399
425
|
end
|
400
426
|
|
427
|
+
context "when given the specs flag" do
|
428
|
+
|
429
|
+
let(:argv) { %w{ new_cookbook --specs } }
|
430
|
+
|
431
|
+
it "configures the generator context with specs mode enabled" do
|
432
|
+
cookbook_generator.read_and_validate_params
|
433
|
+
cookbook_generator.setup_context
|
434
|
+
expect(generator_context.specs).to be(true)
|
435
|
+
end
|
436
|
+
|
437
|
+
it "creates a new cookbook" do
|
438
|
+
Dir.chdir(tempdir) do
|
439
|
+
allow(cookbook_generator.chef_runner).to receive(:stdout).and_return(stdout_io)
|
440
|
+
expect(cookbook_generator.run).to eq(0)
|
441
|
+
end
|
442
|
+
generated_files = Dir.glob("#{tempdir}/new_cookbook/**/*", File::FNM_DOTMATCH)
|
443
|
+
expected_cookbook_files_specs.each do |expected_file|
|
444
|
+
expect(generated_files).to include(expected_file)
|
445
|
+
end
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
401
449
|
context "when given the verbose flag" do
|
402
450
|
|
403
451
|
let(:argv) { %w{ new_cookbook --verbose } }
|
@@ -594,6 +642,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
594
642
|
end
|
595
643
|
|
596
644
|
include_examples "chefspec_spec_helper_file" do
|
645
|
+
let(:argv) { %w{ new_cookbook --policy --specs } }
|
597
646
|
|
598
647
|
let(:expected_chefspec_spec_helper_content) do
|
599
648
|
<<~SPEC_HELPER
|
@@ -683,6 +732,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
683
732
|
end
|
684
733
|
|
685
734
|
include_examples "chefspec_spec_helper_file" do
|
735
|
+
let(:argv) { %w{ new_cookbook --berks --specs } }
|
686
736
|
|
687
737
|
let(:expected_chefspec_spec_helper_content) do
|
688
738
|
<<~SPEC_HELPER
|
@@ -712,6 +762,7 @@ describe ChefCLI::Command::GeneratorCommands::Cookbook do
|
|
712
762
|
end
|
713
763
|
|
714
764
|
describe "spec/unit/recipes/default_spec.rb" do
|
765
|
+
let(:argv) { %w{ new_cookbook --specs } }
|
715
766
|
let(:file) { File.join(tempdir, "new_cookbook", "spec", "unit", "recipes", "default_spec.rb") }
|
716
767
|
|
717
768
|
include_examples "a generated file", :cookbook_name do
|
@@ -181,7 +181,7 @@ describe ChefCLI::Command::GeneratorCommands::GeneratorGenerator do
|
|
181
181
|
metadata_path = File.join(target_dir, "metadata.rb")
|
182
182
|
metadata_content = IO.read(metadata_path)
|
183
183
|
expected_metadata = <<~METADATA
|
184
|
-
name
|
184
|
+
name File.basename(File.dirname(__FILE__))
|
185
185
|
description 'Custom code generator cookbook for use with #{ChefCLI::Dist::PRODUCT}'
|
186
186
|
version '0.1.0'
|
187
187
|
|
@@ -264,8 +264,8 @@ describe ChefCLI::Command::ShellInit do
|
|
264
264
|
{
|
265
265
|
"exec" => "Runs the command in context of the embedded ruby",
|
266
266
|
"env" => "Prints environment variables used by #{ChefCLI::Dist::PRODUCT}",
|
267
|
-
"gem" => "Runs the `gem` command in context of the embedded
|
268
|
-
"generate" => "Generate a new
|
267
|
+
"gem" => "Runs the `gem` command in context of the embedded Ruby",
|
268
|
+
"generate" => "Generate a new repository, cookbook, or other component",
|
269
269
|
}
|
270
270
|
end
|
271
271
|
|
@@ -276,17 +276,17 @@ describe ChefCLI::Command::ShellInit do
|
|
276
276
|
|
277
277
|
let(:expected_completion_function) do
|
278
278
|
<<~END_COMPLETION
|
279
|
+
|
279
280
|
# Fish Shell command-line completions for #{ChefCLI::Dist::PRODUCT}
|
280
281
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
282
|
+
# set a list of all the chef commands in the Ruby chef-cli
|
283
|
+
set -l chef_commands exec env gem generate;
|
284
|
+
|
285
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a exec -d "Runs the command in context of the embedded ruby";
|
286
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a env -d "Prints environment variables used by #{ChefCLI::Dist::PRODUCT}";
|
287
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a gem -d "Runs the `gem` command in context of the embedded Ruby";
|
288
|
+
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a generate -d "Generate a new repository, cookbook, or other component";
|
285
289
|
|
286
|
-
complete -c chef -f -n '__fish_chef_no_command' -a exec -d "Runs the command in context of the embedded ruby"
|
287
|
-
complete -c chef -f -n '__fish_chef_no_command' -a env -d "Prints environment variables used by Chef Workstation"
|
288
|
-
complete -c chef -f -n '__fish_chef_no_command' -a gem -d "Runs the `gem` command in context of the embedded ruby"
|
289
|
-
complete -c chef -f -n '__fish_chef_no_command' -a generate -d "Generate a new app, cookbook, or component"
|
290
290
|
END_COMPLETION
|
291
291
|
end
|
292
292
|
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2014-2018 Chef Software Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require "spec_helper"
|
18
|
+
require "chef-cli/helpers"
|
19
|
+
|
20
|
+
describe ChefCLI::Helpers do
|
21
|
+
context "path_check!" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(Gem).to receive(:ruby).and_return(ruby_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when installed via omnibus" do
|
28
|
+
before do
|
29
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_install?).and_return true
|
30
|
+
end
|
31
|
+
|
32
|
+
context "on unix" do
|
33
|
+
|
34
|
+
let(:user_bin_dir) { File.expand_path(File.join(Gem.user_dir, "bin")) }
|
35
|
+
let(:omnibus_embedded_bin_dir) { "/opt/chef-workstation/embedded/bin" }
|
36
|
+
let(:omnibus_bin_dir) { "/opt/chef-workstation/bin" }
|
37
|
+
let(:expected_PATH) { [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ] }
|
38
|
+
let(:expected_GEM_ROOT) { Gem.default_dir }
|
39
|
+
let(:expected_GEM_HOME) { Gem.user_dir }
|
40
|
+
let(:expected_GEM_PATH) { Gem.path.join(File::PATH_SEPARATOR) }
|
41
|
+
let(:ruby_path) { "/opt/chef-workstation/embedded/bin/ruby" }
|
42
|
+
|
43
|
+
it "#omnibus_env path" do
|
44
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_bin_dir).and_return("/opt/chef-workstation/bin")
|
45
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_embedded_bin_dir).and_return("/opt/chef-workstation/embedded/bin")
|
46
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_env).and_return(
|
47
|
+
"PATH" => expected_PATH.flatten.uniq.join(File::PATH_SEPARATOR),
|
48
|
+
"GEM_ROOT" => expected_GEM_ROOT,
|
49
|
+
"GEM_HOME" => expected_GEM_HOME,
|
50
|
+
"GEM_PATH" => expected_GEM_PATH
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "on windows" do
|
56
|
+
let(:ruby_path) { "c:/opscode/chef-workstation/embedded/bin/ruby.exe" }
|
57
|
+
let(:user_bin_dir) { File.expand_path(File.join(Gem.user_dir, "bin")) }
|
58
|
+
let(:omnibus_embedded_bin_dir) { "c:/opscode/chef-workstation/embedded/bin" }
|
59
|
+
let(:omnibus_bin_dir) { "c:/opscode/chef-workstation/bin" }
|
60
|
+
let(:expected_GEM_ROOT) { Gem.default_dir }
|
61
|
+
let(:expected_GEM_HOME) { Gem.user_dir }
|
62
|
+
let(:expected_GEM_PATH) { Gem.path.join(File::PATH_SEPARATOR) }
|
63
|
+
let(:omnibus_root) { "c:/opscode/chef-workstation" }
|
64
|
+
let(:expected_PATH) { [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ] }
|
65
|
+
|
66
|
+
before do
|
67
|
+
allow(ChefCLI::Helpers).to receive(:expected_omnibus_root).and_return(ruby_path)
|
68
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_install?).and_return(true)
|
69
|
+
allow(Chef::Platform).to receive(:windows?).and_return(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "#omnibus_env path" do
|
73
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_bin_dir).and_return("c:/opscode/chef-workstation/bin")
|
74
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_embedded_bin_dir).and_return("c:/opscode/chef-workstation/embedded/bin")
|
75
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_env).and_return(
|
76
|
+
"PATH" => expected_PATH.flatten.uniq.join(File::PATH_SEPARATOR),
|
77
|
+
"GEM_ROOT" => expected_GEM_ROOT,
|
78
|
+
"GEM_HOME" => expected_GEM_HOME,
|
79
|
+
"GEM_PATH" => expected_GEM_PATH
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when not installed via omnibus" do
|
86
|
+
|
87
|
+
before do
|
88
|
+
allow(ChefCLI::Helpers).to receive(:omnibus_install?).and_return false
|
89
|
+
end
|
90
|
+
let(:ruby_path) { "/Users/bog/.lots_o_rubies/2.1.2/bin/ruby" }
|
91
|
+
let(:expected_root_path) { "/Users/bog/.lots_o_rubies" }
|
92
|
+
|
93
|
+
before do
|
94
|
+
allow(File).to receive(:exist?).with(expected_root_path).and_return(false)
|
95
|
+
|
96
|
+
%i{
|
97
|
+
omnibus_root
|
98
|
+
omnibus_bin_dir
|
99
|
+
omnibus_embedded_bin_dir
|
100
|
+
}.each do |method_name|
|
101
|
+
allow(ChefCLI::Helpers).to receive(method_name).and_raise(ChefCLI::OmnibusInstallNotFound.new)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "skips the sanity check without error" do
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-cli
|
@@ -376,6 +376,7 @@ files:
|
|
376
376
|
- lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/metadata.rb.erb
|
377
377
|
- lib/chef-cli/skeletons/code_generator/templates/default/build_cookbook/recipe.rb.erb
|
378
378
|
- lib/chef-cli/skeletons/code_generator/templates/default/cookbook_file.erb
|
379
|
+
- lib/chef-cli/skeletons/code_generator/templates/default/delivery-project.toml.erb
|
379
380
|
- lib/chef-cli/skeletons/code_generator/templates/default/helpers.rb.erb
|
380
381
|
- lib/chef-cli/skeletons/code_generator/templates/default/inspec_default_test.rb.erb
|
381
382
|
- lib/chef-cli/skeletons/code_generator/templates/default/kitchen.yml.erb
|
@@ -528,6 +529,7 @@ files:
|
|
528
529
|
- spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb
|
529
530
|
- spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb
|
530
531
|
- spec/unit/generator_spec.rb
|
532
|
+
- spec/unit/helpers_spec.rb
|
531
533
|
- spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb
|
532
534
|
- spec/unit/pager_spec.rb
|
533
535
|
- spec/unit/policyfile/artifactory_cookbook_source_spec.rb
|
@@ -743,6 +745,7 @@ test_files:
|
|
743
745
|
- spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb
|
744
746
|
- spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb
|
745
747
|
- spec/unit/generator_spec.rb
|
748
|
+
- spec/unit/helpers_spec.rb
|
746
749
|
- spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb
|
747
750
|
- spec/unit/pager_spec.rb
|
748
751
|
- spec/unit/policyfile/artifactory_cookbook_source_spec.rb
|