Class: ChefCLI::Command::Env

Inherits:
Base
  • Object
show all
Defined in:
lib/chef-cli/command/env.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#check_license_acceptance, #needs_help?, #needs_version?, #run_with_default_options

Methods included from Helpers

#err, #fetch_chef_cli_version_pkg, #get_pkg_install_path, #get_pkg_prefix, #git_bin_dir, #git_windows_bin_dir, #habitat_chef_dke?, #habitat_env, #habitat_install?, #habitat_standalone?, #msg, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_expand_path, #omnibus_install?, #omnibus_root, #package_home, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix

Constructor Details

#initialize(*args) ⇒ Env

Returns a new instance of Env.



36
37
38
39
# File 'lib/chef-cli/command/env.rb', line 36

def initialize(*args)
  super
  @ui = UI.new
end

Instance Attribute Details

#uiObject

Returns the value of attribute ui.



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

def ui
  @ui
end

Instance Method Details

#gem_environmentObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/chef-cli/command/env.rb', line 90

def gem_environment
  h = {}
  if habitat_install?
    # Habitat-specific environment variables
    h["GEM ROOT"] = habitat_env(show_warning: true)["GEM_ROOT"]
    h["GEM HOME"] = habitat_env(show_warning: true)["GEM_HOME"]
    h["GEM PATHS"] = habitat_env(show_warning: true)["GEM_PATH"].split(File::PATH_SEPARATOR)
  elsif omnibus_install?
    # Omnibus-specific environment variables
    h["GEM ROOT"] = omnibus_env["GEM_ROOT"]
    h["GEM HOME"] = omnibus_env["GEM_HOME"]
    h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR)
  else
    # Fallback to system environment variables if neither Omnibus nor Habitat
    h["GEM_ROOT"] = ENV["GEM_ROOT"] if ENV.key?("GEM_ROOT")
    h["GEM_HOME"] = ENV["GEM_HOME"] if ENV.key?("GEM_HOME")
    h["GEM PATHS"] = ENV["GEM_PATH"].split(File::PATH_SEPARATOR) if ENV.key?("GEM_PATH") && !ENV["GEM_PATH"].nil?
  end
  h
end

#get_product_infoObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/chef-cli/command/env.rb', line 50

def get_product_info
  if omnibus_install?
    ChefCLI::Dist::PRODUCT
  elsif habitat_chef_dke?
    ChefCLI::Dist::CHEF_DK_CLI_PACKAGE
  elsif habitat_standalone?
    ChefCLI::Dist::CHEF_CLI_PACKAGE
  else
    ChefCLI::Dist::PRODUCT
  end
end

#pathsObject



111
112
113
114
115
116
# File 'lib/chef-cli/command/env.rb', line 111

def paths
  env = habitat_install? ? habitat_env(show_warning: true) : omnibus_env
  env["PATH"].split(File::PATH_SEPARATOR)
rescue OmnibusInstallNotFound
  ENV["PATH"].split(File::PATH_SEPARATOR)
end

#policyfile_configObject



118
119
120
121
122
123
# File 'lib/chef-cli/command/env.rb', line 118

def policyfile_config
  {}.tap do |h|
    h["Cache Path"] = CookbookOmnifetch.cache_path
    h["Storage Path"] = CookbookOmnifetch.storage_path.to_s
  end
end

#ruby_infoObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef-cli/command/env.rb', line 78

def ruby_info
  {}.tap do |ruby|
    ruby["Executable"] = Gem.ruby
    ruby["Version"] = RUBY_VERSION
    ruby["RubyGems"] = {}.tap do |rubygems|
      rubygems["RubyGems Version"] = Gem::VERSION
      rubygems["RubyGems Platforms"] = Gem.platforms.map(&:to_s)
      rubygems["Gem Environment"] = gem_environment
    end
  end
end

#run(params) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/chef-cli/command/env.rb', line 41

def run(params)
  info = {}
  product_name = get_product_info
  info[product_name] = workstation_info
  info["Ruby"] = ruby_info
  info["Path"] = paths
  ui.msg YAML.dump(info)
end

#workstation_infoObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chef-cli/command/env.rb', line 62

def workstation_info
  info = { "Version" => ChefCLI::VERSION }
  if omnibus_install?
    info["Home"] = package_home
    info["Install Directory"] = omnibus_root
    info["Policyfile Config"] = policyfile_config
  elsif habitat_chef_dke? || habitat_standalone?
    info["Home"] = package_home
    info["Install Directory"] = get_pkg_install_path
    info["Policyfile Config"] = policyfile_config
  else
    info["Version"] = "Not running from within Workstation"
  end
  info
end