Module: ChefCLI::Helpers
- Extended by:
- Helpers
- Included in:
- CLI, Command::Base, CookbookProfiler::Git, Helpers, Policyfile::UndoStack, PolicyfileServices::Install, PolicyfileServices::Push, PolicyfileServices::UpdateAttributes
- Defined in:
- lib/chef-cli/helpers.rb
Instance Method Summary collapse
- #err(message) ⇒ Object
-
#git_bin_dir ⇒ Object
Unix users do not want git on their path if they already have it installed.
-
#git_windows_bin_dir ⇒ Object
In our Windows ChefCLI omnibus package we include Git For Windows, which has a bunch of helpful unix utilties (like ssh, scp, etc.) bundled with it.
- #msg(message) ⇒ Object
- #omnibus_bin_dir ⇒ Object
- #omnibus_embedded_bin_dir ⇒ Object
-
#omnibus_env ⇒ Object
environment vars for omnibus.
- #omnibus_expand_path(*paths) ⇒ Object
-
#omnibus_install? ⇒ Boolean
Locates the omnibus directories.
- #omnibus_root ⇒ Object
- #package_home ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
-
#system_command(*command_args) ⇒ Object
Runs given commands using mixlib-shellout.
-
#usr_bin_path(command) ⇒ Object
Returns the full path to the given command under usr_bin_prefix.
-
#usr_bin_prefix ⇒ Object
Returns the directory that contains our main symlinks.
Instance Method Details
#err(message) ⇒ Object
37 38 39 |
# File 'lib/chef-cli/helpers.rb', line 37 def err() stderr.print("#{}\n") end |
#git_bin_dir ⇒ Object
Unix users do not want git on their path if they already have it installed. Because we put ‘embedded/bin` on the path we must move the git binaries somewhere else that we can append to the end of the path. This is only a temporary solution - see github.com/chef/chef-cli/issues/854 for a better proposed solution.
103 104 105 |
# File 'lib/chef-cli/helpers.rb', line 103 def git_bin_dir @git_bin_dir ||= File.(File.join(omnibus_root, "gitbin")) end |
#git_windows_bin_dir ⇒ Object
In our Windows ChefCLI omnibus package we include Git For Windows, which has a bunch of helpful unix utilties (like ssh, scp, etc.) bundled with it
109 110 111 |
# File 'lib/chef-cli/helpers.rb', line 109 def git_windows_bin_dir @git_windows_bin_dir ||= File.(File.join(omnibus_root, "embedded", "git", "usr", "bin")) end |
#msg(message) ⇒ Object
41 42 43 |
# File 'lib/chef-cli/helpers.rb', line 41 def msg() stdout.print("#{}\n") end |
#omnibus_bin_dir ⇒ Object
67 68 69 |
# File 'lib/chef-cli/helpers.rb', line 67 def omnibus_bin_dir @omnibus_bin_dir ||= (omnibus_root, "bin") end |
#omnibus_embedded_bin_dir ⇒ Object
71 72 73 |
# File 'lib/chef-cli/helpers.rb', line 71 def @omnibus_embedded_bin_dir ||= (omnibus_root, "embedded", "bin") end |
#omnibus_env ⇒ Object
environment vars for omnibus
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/chef-cli/helpers.rb', line 116 def omnibus_env @omnibus_env ||= begin user_bin_dir = File.(File.join(Gem.user_dir, "bin")) path = [ omnibus_bin_dir, user_bin_dir, , ENV["PATH"].split(File::PATH_SEPARATOR) ] path << git_bin_dir if Dir.exist?(git_bin_dir) path << git_windows_bin_dir if Dir.exist?(git_windows_bin_dir) { "PATH" => path.flatten.uniq.join(File::PATH_SEPARATOR), "GEM_ROOT" => Gem.default_dir, "GEM_HOME" => Gem.user_dir, "GEM_PATH" => Gem.path.join(File::PATH_SEPARATOR), } end end |
#omnibus_expand_path(*paths) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/chef-cli/helpers.rb', line 132 def (*paths) dir = File.(File.join(paths)) raise OmnibusInstallNotFound.new unless dir && File.directory?(dir) dir end |
#omnibus_install? ⇒ Boolean
Locates the omnibus directories
56 57 58 59 60 61 |
# File 'lib/chef-cli/helpers.rb', line 56 def omnibus_install? # We also check if the location we're running from (omnibus_root is relative to currently-running ruby) # includes the version manifest that omnibus packages ship with. If it doesn't, then we're running locally # or out of a gem - so not as an 'omnibus install' File.exist?(expected_omnibus_root) && File.exist?(File.join(expected_omnibus_root, "version-manifest.json")) end |
#omnibus_root ⇒ Object
63 64 65 |
# File 'lib/chef-cli/helpers.rb', line 63 def omnibus_root @omnibus_root ||= (expected_omnibus_root) end |
#package_home ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/chef-cli/helpers.rb', line 75 def package_home @package_home ||= begin package_home_set = !([nil, ""].include? ENV["CHEF_WORKSTATION_HOME"]) if package_home_set ENV["CHEF_WORKSTATION_HOME"] else default_package_home end end end |
#stderr ⇒ Object
49 50 51 |
# File 'lib/chef-cli/helpers.rb', line 49 def stderr $stderr end |
#stdout ⇒ Object
45 46 47 |
# File 'lib/chef-cli/helpers.rb', line 45 def stdout $stdout end |
#system_command(*command_args) ⇒ Object
Runs given commands using mixlib-shellout
31 32 33 34 35 |
# File 'lib/chef-cli/helpers.rb', line 31 def system_command(*command_args) cmd = Mixlib::ShellOut.new(*command_args) cmd.run_command cmd end |
#usr_bin_path(command) ⇒ Object
Returns the full path to the given command under usr_bin_prefix
94 95 96 |
# File 'lib/chef-cli/helpers.rb', line 94 def usr_bin_path(command) File.join(usr_bin_prefix, command) end |
#usr_bin_prefix ⇒ Object
Returns the directory that contains our main symlinks. On Mac we place all of our symlinks under /usr/local/bin on other platforms they are under /usr/bin
89 90 91 |
# File 'lib/chef-cli/helpers.rb', line 89 def usr_bin_prefix @usr_bin_prefix ||= macos? ? "/usr/local/bin" : "/usr/bin" end |