Skip to content

Commit 63a79bb

Browse files
authored
Merge pull request #263 from chef/CHEF-18664-update-the-shell-init-command
[CHEF-18664] Updated the shell-init command to work with habitat and omnibus installations
2 parents 23d7601 + f16dfea commit 63a79bb

File tree

20 files changed

+246
-49
lines changed

20 files changed

+246
-49
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ group :test do
1111
gem "rspec-mocks", "~> 3.8"
1212
gem "cookstyle"
1313
gem "chefstyle"
14-
gem "test-kitchen"
14+
gem "faraday_middleware"
15+
gem "chef-test-kitchen-enterprise", git: "https://github.com/chef/chef-test-kitchen-enterprise", branch: "main"
1516
gem "simplecov", require: false
1617
end
1718

chef-cli.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ Gem::Specification.new do |gem|
5050
gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output
5151
gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ
5252
gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3"
53-
gem.add_dependency "chef-licensing", ">= 1.0.2"
53+
gem.add_dependency "chef-licensing", "~> 1.0"
5454
end

habitat/plan.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ function Invoke-Build {
4747
bundle install
4848

4949
gem build chef-cli.gemspec
50-
Write-BuildLine " ** Using gem to install"
51-
gem install chef-cli-*.gem --no-document
52-
50+
Write-BuildLine " ** Using gem to install"
51+
gem install chef-cli-*.gem --no-document
52+
ruby ./post-bundle-install.rb
5353

5454
If ($lastexitcode -ne 0) { Exit $lastexitcode }
5555
} finally {

habitat/plan.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pkg_build_deps=(
99
core/sed
1010
core/gcc
1111
core/libarchive
12+
core/git
1213
)
1314
pkg_bin_dirs=(bin)
1415

@@ -42,6 +43,7 @@ do_build() {
4243
bundle config --local silence_root_warning 1
4344
bundle install
4445
gem build chef-cli.gemspec
46+
ruby ./post-bundle-install.rb
4547
}
4648
do_install() {
4749
export GEM_HOME="$pkg_prefix/vendor"

lib/chef-cli/command/env.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def gem_environment
8585
end
8686

8787
def paths
88-
omnibus_env["PATH"].split(File::PATH_SEPARATOR)
88+
env = habitat_install? ? habitat_env : omnibus_env
89+
env["PATH"].split(File::PATH_SEPARATOR)
8990
rescue OmnibusInstallNotFound
9091
ENV["PATH"].split(File::PATH_SEPARATOR)
9192
end

lib/chef-cli/command/exec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class Exec < ChefCLI::Command::Base
3030
def run(params)
3131
# Set ENV directly on the "parent" process (us) before running #exec to
3232
# ensure the custom PATH is honored when finding the command to exec
33-
omnibus_env.each { |var, value| ENV[var] = value }
33+
env = habitat_install? ? habitat_env : omnibus_env
34+
env.each { |var, value| ENV[var] = value }
3435
exec(*params)
3536
raise "Exec failed without an exception, your ruby is buggy" # should never get here
3637
end

lib/chef-cli/command/license.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def run(params)
7575
else
7676
ChefCLI::Licensing::Base.send(remaining_args[0])
7777
end
78+
rescue ChefLicensing::LicenseKeyFetcher::LicenseKeyNotFetchedError
79+
ui.msg("License key not fetched. Please try again.")
7880
end
7981

8082
def debug?

lib/chef-cli/command/shell_init.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Mixlib
2929
module ChefCLI
3030

3131
class ShellCompletionTemplateContext
32+
include ChefCLI::Helpers
3233

3334
def commands
3435
ChefCLI.commands_map.command_specs.inject({}) do |cmd_info, (_key, cmd_spec)|
@@ -40,6 +41,10 @@ def commands
4041
def get_binding
4142
binding
4243
end
44+
45+
def habitat?
46+
habitat_install?
47+
end
4348
end
4449

4550
module Command
@@ -103,7 +108,7 @@ def run(argv)
103108
return 1
104109
end
105110

106-
env = omnibus_env.dup
111+
env = (habitat_install? ? habitat_env : omnibus_env).dup
107112
path = env.delete("PATH")
108113
export(shell_name, "PATH", path)
109114
env.each do |var_name, value|

lib/chef-cli/completions/bash.sh.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ _chef_comp() {
22
local COMMANDS="<%= commands.keys.join(' ')-%>"
33
COMPREPLY=($(compgen -W "$COMMANDS" -- ${COMP_WORDS[COMP_CWORD]} ))
44
}
5-
complete -F _chef_comp chef
5+
complete -F _chef_comp <%= habitat? ? "chef-cli" : "chef" %>

lib/chef-cli/completions/chef.fish.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
set -l chef_commands <%= commands.keys.join(' ') %>;
66

77
<% commands.each do |command, desc| -%>
8-
complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a <%= command %> -d "<%= desc %>";
8+
complete -c <%= habitat? ? "chef-cli" : "chef" %> -f -n "not __fish_seen_subcommand_from $chef_commands" -a <%= command %> -d "<%= desc %>";
99
<% end -%>

0 commit comments

Comments
 (0)