Module: ChefCLI::Helpers

Instance Method Summary collapse

Instance Method Details

#err(message) ⇒ Object



34
35
36
# File 'lib/chef-cli/helpers.rb', line 34

def err(message)
  stderr.print("#{message}\n")
end

#git_bin_dirObject

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.



100
101
102
# File 'lib/chef-cli/helpers.rb', line 100

def git_bin_dir
  @git_bin_dir ||= File.expand_path(File.join(omnibus_root, "gitbin"))
end

#git_windows_bin_dirObject

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



106
107
108
# File 'lib/chef-cli/helpers.rb', line 106

def git_windows_bin_dir
  @git_windows_bin_dir ||= File.expand_path(File.join(omnibus_root, "embedded", "git", "usr", "bin"))
end

#msg(message) ⇒ Object



38
39
40
# File 'lib/chef-cli/helpers.rb', line 38

def msg(message)
  stdout.print("#{message}\n")
end

#omnibus_bin_dirObject



64
65
66
# File 'lib/chef-cli/helpers.rb', line 64

def omnibus_bin_dir
  @omnibus_bin_dir ||= omnibus_expand_path(omnibus_root, "bin")
end

#omnibus_embedded_bin_dirObject



68
69
70
# File 'lib/chef-cli/helpers.rb', line 68

def omnibus_embedded_bin_dir
  @omnibus_embedded_bin_dir ||= omnibus_expand_path(omnibus_root, "embedded", "bin")
end

#omnibus_envObject

environment vars for omnibus



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/chef-cli/helpers.rb', line 113

def omnibus_env
  @omnibus_env ||=
    begin
      user_bin_dir = File.expand_path(File.join(Gem.user_dir, "bin"))
      path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_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

Returns:

  • (Boolean)


53
54
55
56
57
58
# File 'lib/chef-cli/helpers.rb', line 53

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_rootObject



60
61
62
# File 'lib/chef-cli/helpers.rb', line 60

def omnibus_root
  @omnibus_root ||= omnibus_expand_path(expected_omnibus_root)
end

#package_homeObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/chef-cli/helpers.rb', line 72

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

#stderrObject



46
47
48
# File 'lib/chef-cli/helpers.rb', line 46

def stderr
  $stderr
end

#stdoutObject



42
43
44
# File 'lib/chef-cli/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-cli/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



91
92
93
# File 'lib/chef-cli/helpers.rb', line 91

def usr_bin_path(command)
  File.join(usr_bin_prefix, command)
end

#usr_bin_prefixObject

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



86
87
88
# File 'lib/chef-cli/helpers.rb', line 86

def usr_bin_prefix
  @usr_bin_prefix ||= os_x? ? "/usr/local/bin" : "/usr/bin"
end