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, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_env, #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.



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

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

Instance Attribute Details

#uiObject

Returns the value of attribute ui.



31
32
33
# File 'lib/chef-cli/command/env.rb', line 31

def ui
  @ui
end

Instance Method Details

#gem_environmentObject



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

def gem_environment
  h = {}
  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)
rescue OmnibusInstallNotFound
  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.key?("GEM_PATH").nil?
ensure
  h
end

#pathsObject



84
85
86
87
88
# File 'lib/chef-cli/command/env.rb', line 84

def paths
  omnibus_env["PATH"].split(File::PATH_SEPARATOR)
rescue OmnibusInstallNotFound
  ENV["PATH"].split(File::PATH_SEPARATOR)
end

#policyfile_configObject



90
91
92
93
94
95
# File 'lib/chef-cli/command/env.rb', line 90

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

#ruby_infoObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chef-cli/command/env.rb', line 59

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



38
39
40
41
42
43
44
# File 'lib/chef-cli/command/env.rb', line 38

def run(params)
  info = {}
  info["#{ChefCLI::Dist::PRODUCT}"] = workstation_info
  info["Ruby"] = ruby_info
  info["Path"] = paths
  ui.msg info.to_yaml
end

#workstation_infoObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef-cli/command/env.rb', line 46

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