Module: ChefDK::Helpers
- Extended by:
- Helpers
- Included in:
- CLI, Command::Base, Command::Verify, ComponentTest, CookbookProfiler::Git, Helpers, Policyfile::UndoStack, PolicyfileServices::Install, PolicyfileServices::Push, PolicyfileServices::UpdateAttributes
- Defined in:
- lib/chef-dk/helpers.rb
Instance Method Summary collapse
- #chefdk_home ⇒ Object
- #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 ChefDK 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_apps_dir ⇒ Object
- #omnibus_bin_dir ⇒ Object
- #omnibus_chefdk_location ⇒ Object
- #omnibus_embedded_bin_dir ⇒ Object
-
#omnibus_env ⇒ Object
environment vars for omnibus.
-
#omnibus_install? ⇒ Boolean
Locates the omnibus directories.
- #omnibus_root ⇒ 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
#chefdk_home ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/chef-dk/helpers.rb', line 78 def chefdk_home @chefdk_home ||= begin chefdk_home_set = !([nil, ""].include? ENV["CHEFDK_HOME"]) if chefdk_home_set ENV["CHEFDK_HOME"] else default_chefdk_home end end end |
#err(message) ⇒ Object
34 35 36 |
# File 'lib/chef-dk/helpers.rb', line 34 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-dk/issues/854 for a better proposed solution.
106 107 108 |
# File 'lib/chef-dk/helpers.rb', line 106 def git_bin_dir @git_bin_dir ||= File.(File.join(omnibus_root, "gitbin")) end |
#git_windows_bin_dir ⇒ Object
In our Windows ChefDK omnibus package we include Git For Windows, which has a bunch of helpful unix utilties (like ssh, scp, etc.) bundled with it
112 113 114 |
# File 'lib/chef-dk/helpers.rb', line 112 def git_windows_bin_dir @git_windows_bin_dir ||= File.(File.join(omnibus_root, "embedded", "git", "usr", "bin")) end |
#msg(message) ⇒ Object
38 39 40 |
# File 'lib/chef-dk/helpers.rb', line 38 def msg() stdout.print("#{}\n") end |
#omnibus_apps_dir ⇒ Object
62 63 64 |
# File 'lib/chef-dk/helpers.rb', line 62 def omnibus_apps_dir @ominbus_apps_dir ||= (omnibus_root, "embedded", "apps") end |
#omnibus_bin_dir ⇒ Object
66 67 68 |
# File 'lib/chef-dk/helpers.rb', line 66 def omnibus_bin_dir @omnibus_bin_dir ||= (omnibus_root, "bin") end |
#omnibus_chefdk_location ⇒ Object
74 75 76 |
# File 'lib/chef-dk/helpers.rb', line 74 def omnibus_chefdk_location @omnibus_chefdk_location ||= File.("embedded/apps/chef-dk", expected_omnibus_root) end |
#omnibus_embedded_bin_dir ⇒ Object
70 71 72 |
# File 'lib/chef-dk/helpers.rb', line 70 def @omnibus_embedded_bin_dir ||= (omnibus_root, "embedded", "bin") end |
#omnibus_env ⇒ Object
environment vars for omnibus
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/chef-dk/helpers.rb', line 119 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"] ] path << git_bin_dir if Dir.exist?(git_bin_dir) path << git_windows_bin_dir if Dir.exist?(git_windows_bin_dir) { "PATH" => path.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_install? ⇒ Boolean
Locates the omnibus directories
54 55 56 |
# File 'lib/chef-dk/helpers.rb', line 54 def omnibus_install? File.exist?(omnibus_chefdk_location) end |
#omnibus_root ⇒ Object
58 59 60 |
# File 'lib/chef-dk/helpers.rb', line 58 def omnibus_root @omnibus_root ||= (expected_omnibus_root) end |
#stderr ⇒ Object
46 47 48 |
# File 'lib/chef-dk/helpers.rb', line 46 def stderr $stderr end |
#stdout ⇒ Object
42 43 44 |
# File 'lib/chef-dk/helpers.rb', line 42 def stdout $stdout end |
#system_command(*command_args) ⇒ Object
Runs given commands using mixlib-shellout
28 29 30 31 32 |
# File 'lib/chef-dk/helpers.rb', line 28 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
97 98 99 |
# File 'lib/chef-dk/helpers.rb', line 97 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
92 93 94 |
# File 'lib/chef-dk/helpers.rb', line 92 def usr_bin_prefix @usr_bin_prefix ||= os_x? ? "/usr/local/bin" : "/usr/bin" end |