diff --git a/habitat/plan.sh b/habitat/plan.sh index e04cf284b..41325a805 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -67,7 +67,8 @@ wrap_ruby_bin() { set -e # Set binary path that allows InSpec to use non-Hab pkg binaries -export PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:$pkg_prefix/vendor/bin:\$PATH" +# Include Ruby bin directory so chef-cli exec can find gem, etc. +export PATH="$(pkg_path_for ${ruby_pkg})/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:$pkg_prefix/vendor/bin:\$PATH" # Set Ruby paths defined from 'do_setup_environment()' export GEM_HOME="$pkg_prefix/vendor" diff --git a/lib/chef-cli/command/base.rb b/lib/chef-cli/command/base.rb index e3ccfd28a..a40889c7e 100644 --- a/lib/chef-cli/command/base.rb +++ b/lib/chef-cli/command/base.rb @@ -39,7 +39,7 @@ class Base option :version, short: "-v", long: "--version", - description: "Show #{ChefCLI::Dist::PRODUCT} version", + description: "Show #{ChefCLI::Dist::CLI_PRODUCT} version", boolean: true option :debug, @@ -67,7 +67,7 @@ def run_with_default_options(enforce_license, params = [ ]) msg(opt_parser.to_s) 0 elsif needs_version?(params) - msg("#{ChefCLI::Dist::PRODUCT} version: #{ChefCLI::VERSION}") + msg("#{ChefCLI::Dist::CLI_PRODUCT} version: #{ChefCLI::VERSION}") 0 else check_license_acceptance if enforce_license diff --git a/lib/chef-cli/command/clean_policy_cookbooks.rb b/lib/chef-cli/command/clean_policy_cookbooks.rb index 9fda99f7b..2dd39813f 100644 --- a/lib/chef-cli/command/clean_policy_cookbooks.rb +++ b/lib/chef-cli/command/clean_policy_cookbooks.rb @@ -32,7 +32,7 @@ class CleanPolicyCookbooks < Base `#{ChefCLI::Dist::EXEC} clean-policy-cookbooks` deletes unused Policyfile cookbooks. Cookbooks are considered unused when they are not referenced by any Policyfile revision on the #{ChefCLI::Dist::SERVER_PRODUCT}. Note that cookbooks which are referenced by "orphaned" policy - revisions are not removed, so you may wish to run `chef clean-policy-revisions` + revisions are not removed, so you may wish to run `chef-cli clean-policy-revisions` to remove orphaned policies before running this command. See our detailed README for more information: diff --git a/lib/chef-cli/command/delete_policy.rb b/lib/chef-cli/command/delete_policy.rb index d22088f36..0ff7b78eb 100644 --- a/lib/chef-cli/command/delete_policy.rb +++ b/lib/chef-cli/command/delete_policy.rb @@ -31,7 +31,7 @@ class DeletePolicy < Base `#{ChefCLI::Dist::EXEC} delete-policy POLICY_NAME` deletes all revisions of the policy `POLICY_NAME` on the configured #{ChefCLI::Dist::SERVER_PRODUCT}. All policy revisions will be - backed up locally, allowing you to undo this operation via the `chef undelete` + backed up locally, allowing you to undo this operation via the `chef-cli undelete` command. See our detailed README for more information: diff --git a/lib/chef-cli/command/delete_policy_group.rb b/lib/chef-cli/command/delete_policy_group.rb index 9e81e1dc6..1c705f454 100644 --- a/lib/chef-cli/command/delete_policy_group.rb +++ b/lib/chef-cli/command/delete_policy_group.rb @@ -32,7 +32,7 @@ class DeletePolicyGroup < Base `#{ChefCLI::Dist::EXEC} delete-policy-group POLICY_GROUP` deletes the policy group POLICY_GROUP on the configured #{ChefCLI::Dist::SERVER_PRODUCT}. Policy Revisions associated to the policy group are not deleted. The state of the policy group will be backed up locally, allowing - you to undo this operation via the `chef undelete` command. + you to undo this operation via the `chef-cli undelete` command. See our detailed README for more information: diff --git a/lib/chef-cli/command/push_archive.rb b/lib/chef-cli/command/push_archive.rb index cec78fa52..efab48205 100644 --- a/lib/chef-cli/command/push_archive.rb +++ b/lib/chef-cli/command/push_archive.rb @@ -32,7 +32,7 @@ class PushArchive < Base Usage: #{ChefCLI::Dist::EXEC} push-archive POLICY_GROUP ARCHIVE_FILE [options] `#{ChefCLI::Dist::EXEC} push-archive` publishes a policy archive to a #{ChefCLI::Dist::SERVER_PRODUCT}. Policy - archives can be created with `chef export -a`. The policy will be applied to + archives can be created with `chef-cli export -a`. The policy will be applied to the given POLICY_GROUP, which is a set of nodes that share the same run_list and cookbooks. diff --git a/lib/chef-cli/command/undelete.rb b/lib/chef-cli/command/undelete.rb index 0af1e642f..4fd211126 100644 --- a/lib/chef-cli/command/undelete.rb +++ b/lib/chef-cli/command/undelete.rb @@ -31,15 +31,15 @@ class Undelete < Base `#{ChefCLI::Dist::EXEC} undelete` helps you recover quickly if you've deleted a policy or policy group in error. When run with no arguements, it lists the available undo - operations. To undo the last delete operation, use `chef undelete --last`. + operations. To undo the last delete operation, use `chef-cli undelete --last`. CAVEATS: `#{ChefCLI::Dist::EXEC} undelete` doesn't detect conflicts. If a deleted item has been recreated, - running `chef undelete` will overwrite it. + running `chef-cli undelete` will overwrite it. Undo information does not include cookbooks that might be referenced by policies. If you have cleaned the policy cookbooks after the delete operation - you want to reverse, `chef undelete` may not be able to fully restore the + you want to reverse, `chef-cli undelete` may not be able to fully restore the previous state. The delete commands also do not store access control data, so you may have to diff --git a/lib/chef-cli/dist.rb b/lib/chef-cli/dist.rb index f643ce31a..c594f67cd 100644 --- a/lib/chef-cli/dist.rb +++ b/lib/chef-cli/dist.rb @@ -36,7 +36,7 @@ class Dist WORKFLOW = "Chef Workflow (Delivery)".freeze # The chef executable, as in `chef gem install` or `chef generate cookbook` - EXEC = "chef".freeze + EXEC = "chef-cli".freeze # Chef-Zero's product name ZERO_PRODUCT = "Chef Infra Zero".freeze @@ -50,6 +50,6 @@ class Dist # Workstation banner/help text WORKSTATION_DOCS = "https://docs.chef.io/workstation/".freeze - WORKSTATION_HEADER = "The Chef command line tool for managing your infrastructure from your workstation.".freeze + WORKSTATION_HEADER = "This command line tool is used for managing your infrastructure from your workstation.".freeze end end diff --git a/lib/chef-cli/helpers.rb b/lib/chef-cli/helpers.rb index 926a3eb0b..59017c863 100644 --- a/lib/chef-cli/helpers.rb +++ b/lib/chef-cli/helpers.rb @@ -174,10 +174,12 @@ def habitat_env(show_warning: false) raise "Error: Could not determine the vendor package prefix. Ensure #{ChefCLI::Dist::HAB_PKG_NAME} is installed and CHEF_CLI_VERSION is set correctly." unless vendor_pkg_prefix vendor_dir = File.join(vendor_pkg_prefix, "vendor") - # Construct PATH + # Construct PATH including Ruby bin directory for chef-cli exec command + ruby_bin_dir = File.dirname(RbConfig.ruby) path = [ File.join(bin_pkg_prefix, "bin"), File.join(vendor_dir, "bin"), + ruby_bin_dir, # Add Ruby bin directory so exec can find gem etc. ENV["PATH"].split(File::PATH_SEPARATOR), # Preserve existing PATH ].flatten.uniq diff --git a/lib/chef-cli/skeletons/code_generator/files/default/repo/policyfiles/README.md b/lib/chef-cli/skeletons/code_generator/files/default/repo/policyfiles/README.md index 5f3a2cdc6..8c2e7ed80 100644 --- a/lib/chef-cli/skeletons/code_generator/files/default/repo/policyfiles/README.md +++ b/lib/chef-cli/skeletons/code_generator/files/default/repo/policyfiles/README.md @@ -5,20 +5,20 @@ the same filename as the name set in the policyfile itself, and use the Compile the policy with a command like this: ``` -chef install policyfiles/my-app-frontend.rb +chef-cli install policyfiles/my-app-frontend.rb ``` This will create a lockfile `policyfiles/my-app-frontend.lock.json`. -To update locked dependencies, run `chef update` like this: +To update locked dependencies, run `chef-cli update` like this: ``` -chef update policyfiles/my-app-frontend.rb +chef-cli update policyfiles/my-app-frontend.rb ``` You can upload the policy (with associated cookbooks) to the server using a command like: ``` -chef push staging policyfiles/my-app-frontend.rb +chef-cli push staging policyfiles/my-app-frontend.rb ``` diff --git a/spec/shared/a_file_generator.rb b/spec/shared/a_file_generator.rb index 983ff12b7..c5002a29f 100644 --- a/spec/shared/a_file_generator.rb +++ b/spec/shared/a_file_generator.rb @@ -40,7 +40,7 @@ def generator_context let(:argv) { [] } it "emits an error message and exits" do - expected_stdout = "Usage: chef generate #{generator_name} [path/to/cookbook] NAME [options]" + expected_stdout = "Usage: chef-cli generate #{generator_name} [path/to/cookbook] NAME [options]" expect(recipe_generator.run).to eq(1) expect(stdout).to include(expected_stdout) @@ -85,7 +85,7 @@ def generator_context let(:argv) { [ new_file_name ] } it "emits an error message and exits" do - expected_stdout = "Usage: chef generate #{generator_name} [path/to/cookbook] NAME [options]" + expected_stdout = "Usage: chef-cli generate #{generator_name} [path/to/cookbook] NAME [options]" expected_stderr = "Error: Directory #{Dir.pwd} is not a cookbook\n" expect(recipe_generator.run).to eq(1) diff --git a/spec/unit/cli_spec.rb b/spec/unit/cli_spec.rb index 10e1515ab..f820c0417 100644 --- a/spec/unit/cli_spec.rb +++ b/spec/unit/cli_spec.rb @@ -46,9 +46,9 @@ def stderr Patents: #{ChefCLI::Dist::PATENTS} Usage: - chef -h/--help - chef -v/--version - chef command [arguments...] [options...] + chef-cli -h/--help + chef-cli -v/--version + chef-cli command [arguments...] [options...] Available Commands: gem Runs the `gem` command in context of the embedded ruby @@ -290,7 +290,7 @@ def test_result run_cli_with_sanity_check(0) expect(stdout).to eq(base_help_message) expect(stderr).to include("please reverse that order") - expect(stderr).to include("chef shell-init") + expect(stderr).to include("chef-cli shell-init") end it "complains if only embedded is present" do @@ -300,7 +300,7 @@ def test_result run_cli_with_sanity_check(0) expect(stdout).to eq(base_help_message) expect(stderr).to include("you must add") - expect(stderr).to include("chef shell-init") + expect(stderr).to include("chef-cli shell-init") end it "passes when both are present in the correct order" do @@ -349,7 +349,7 @@ def test_result run_cli_with_sanity_check(0) expect(stdout).to eq(base_help_message) expect(stderr).to include("please reverse that order") - expect(stderr).to include("chef shell-init") + expect(stderr).to include("chef-cli shell-init") end it "complains if only embedded is present" do @@ -359,7 +359,7 @@ def test_result run_cli_with_sanity_check(0) expect(stdout).to eq(base_help_message) expect(stderr).to include("you must add") - expect(stderr).to include("chef shell-init") + expect(stderr).to include("chef-cli shell-init") end it "passes when both are present in the correct order" do diff --git a/spec/unit/command/base_spec.rb b/spec/unit/command/base_spec.rb index bfadbac7e..6bc446a65 100644 --- a/spec/unit/command/base_spec.rb +++ b/spec/unit/command/base_spec.rb @@ -78,12 +78,12 @@ def run_command(options) it "should print the version for -v" do run_command(["-v"]) - expect(stdout).to eq("#{ChefCLI::Dist::PRODUCT} version: #{ChefCLI::VERSION}\n") + expect(stdout).to eq("#{ChefCLI::Dist::CLI_PRODUCT} version: #{ChefCLI::VERSION}\n") end it "should print the version for --version" do run_command(["--version"]) - expect(stdout).to eq("#{ChefCLI::Dist::PRODUCT} version: #{ChefCLI::VERSION}\n") + expect(stdout).to eq("#{ChefCLI::Dist::CLI_PRODUCT} version: #{ChefCLI::VERSION}\n") end it "should run the command passing in the custom options for long custom options" do @@ -131,7 +131,7 @@ def run_command(options) -D, --debug Enable stacktraces and other debug output -h, --help Show this message -u, --user If the user exists - -v, --version Show #{ChefCLI::Dist::PRODUCT} version + -v, --version Show #{ChefCLI::Dist::CLI_PRODUCT} version E expect(stdout).to eq(expected) @@ -154,7 +154,7 @@ def run_command(options) -D, --debug Enable stacktraces and other debug output -h, --help Show this message -u, --user If the user exists - -v, --version Show #{ChefCLI::Dist::PRODUCT} version + -v, --version Show #{ChefCLI::Dist::CLI_PRODUCT} version E expect(stdout).to eq(expected) diff --git a/spec/unit/command/env_spec.rb b/spec/unit/command/env_spec.rb index 66ff1c343..222eb7cc0 100644 --- a/spec/unit/command/env_spec.rb +++ b/spec/unit/command/env_spec.rb @@ -29,7 +29,7 @@ let(:omnibus_bin_dir) { "/foo/bin" } it "has a usage banner" do - expect(command_instance.banner).to eq("Usage: chef env") + expect(command_instance.banner).to eq("Usage: chef-cli env") end describe "when running from within an omnibus install" do diff --git a/spec/unit/command/exec_spec.rb b/spec/unit/command/exec_spec.rb index 15fcb46a5..d50dc3465 100644 --- a/spec/unit/command/exec_spec.rb +++ b/spec/unit/command/exec_spec.rb @@ -28,7 +28,7 @@ def run_command end it "has a usage banner" do - expect(command_instance.banner).to eq("Usage: chef exec SYSTEM_COMMAND") + expect(command_instance.banner).to eq("Usage: chef-cli exec SYSTEM_COMMAND") end describe "when locating omnibus directory" do diff --git a/spec/unit/command/generate_spec.rb b/spec/unit/command/generate_spec.rb index 06933477b..9dae86e85 100644 --- a/spec/unit/command/generate_spec.rb +++ b/spec/unit/command/generate_spec.rb @@ -75,7 +75,7 @@ def stderr context "with a generator defined" do let(:expected_help_message) do <<~E - Usage: chef generate GENERATOR [options] + Usage: chef-cli generate GENERATOR [options] Available generators: example this is a test diff --git a/spec/unit/command/generator_commands/cookbook_spec.rb b/spec/unit/command/generator_commands/cookbook_spec.rb index ba5f45396..283b79c50 100644 --- a/spec/unit/command/generator_commands/cookbook_spec.rb +++ b/spec/unit/command/generator_commands/cookbook_spec.rb @@ -131,7 +131,7 @@ def generator_context context "when given invalid/incomplete arguments" do let(:expected_help_message) do - "Usage: chef generate cookbook NAME [options]\n" + "Usage: chef-cli generate cookbook NAME [options]\n" end def with_argv(argv) diff --git a/spec/unit/command/generator_commands/policyfile_spec.rb b/spec/unit/command/generator_commands/policyfile_spec.rb index 45d915469..4fe5bfe65 100644 --- a/spec/unit/command/generator_commands/policyfile_spec.rb +++ b/spec/unit/command/generator_commands/policyfile_spec.rb @@ -212,7 +212,7 @@ def generator_context let(:argv) { %w{ foo bar baz } } it "shows usage and exits" do - expected_stdout = "Usage: chef generate policyfile [NAME] [options]" + expected_stdout = "Usage: chef-cli generate policyfile [NAME] [options]" expect(generator.run).to eq(1) expect(stderr).to include(expected_stdout) diff --git a/spec/unit/helpers_spec.rb b/spec/unit/helpers_spec.rb index 207306766..5ad8e1798 100644 --- a/spec/unit/helpers_spec.rb +++ b/spec/unit/helpers_spec.rb @@ -112,8 +112,9 @@ context "when installed with habitat" do let(:chef_dke_path) { "/hab/pkgs/chef/chef-workstation/1.0.0/123" } let(:cli_hab_path) { "/hab/pkgs/chef/chef-cli/1.0.0/123" } + let(:ruby_bin_dir) { File.dirname(RbConfig.ruby) } let(:expected_gem_root) { Gem.default_dir } - let(:expected_path) { [File.join(chef_dke_path, "bin"), File.join(cli_hab_path, "vendor", "bin"), "/usr/bin:/bin"].flatten } + let(:expected_path) { [File.join(chef_dke_path, "bin"), File.join(cli_hab_path, "vendor", "bin"), ruby_bin_dir, "/usr/bin:/bin"].flatten } let(:expected_env) do { "PATH" => expected_path.join(File::PATH_SEPARATOR),