Method: Chef::Sugar::Shell#version_for

Defined in:
lib/chef/sugar/shell.rb

#version_for(cmd, flag = '--version') ⇒ String

The version for a given command. This method does NOT check if the command exists! It is assumed the command existence has been checked with which or similar. To simply check if an installed version is acceptable, please see installed_at_version.

Assumptions:

1. The command exists.
2. The command outputs version information to +$stdout+ or +$stderr+.
   Did you know that java outputs its version to $stderr?

Parameters:

  • cmd (String)

    the command to find the version for

  • flag (String) (defaults to: '--version')

    the flag to use to get the version

Returns:

  • (String)

    the entire output of the version command (stderr and stdout)



118
119
120
121
122
123
# File 'lib/chef/sugar/shell.rb', line 118

def version_for(cmd, flag = '--version')
  cmd = Mixlib::ShellOut.new("#{cmd} #{flag}")
  cmd.run_command
  cmd.error!
  [cmd.stdout.strip, cmd.stderr.strip].join("\n")
end