chef-workstation icon indicating copy to clipboard operation
chef-workstation copied to clipboard

Move `chef env` to the go CLI

Open tas50 opened this issue 4 years ago • 1 comments

As a user I want `chef` commands to run quickly
So that I can get the information I need to do my job quickly

In order to make the Chef CLI as performant as possible, we should move the chef env command from the chef-cli Ruby app to the chef Go app. This could potentially greatly speed up this command on Windows systems.

tas50 avatar Jul 15 '21 15:07 tas50

To move chef env command we have to rewrite ruby code from chef-cli into the workstation

https://github.com/chef/chef-cli/blob/main/lib/chef-cli/command/env.rb

Moving environment seems straight

  1. Code contains mostly printing versions and environment which can be easily done using the right data structures.

challenges

Printing environment data in yaml format, though we can use some libraries https://zetcode.com/golang/yaml/ https://github.com/go-yaml/yaml

Another challenging point could be, getting the right versions from ruby when we are coding in go or getting the right path.

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


 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

i5pranay93 avatar Oct 11 '21 08:10 i5pranay93