Class: ChefDK::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers, Mixlib::CLI
Defined in:
lib/chef-dk/command/base.rb

Instance Method Summary collapse

Methods included from Helpers

#chefdk_home, #err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix

Constructor Details

#initializeBase

Returns a new instance of Base.



41
42
43
# File 'lib/chef-dk/command/base.rb', line 41

def initialize
  super
end

Instance Method Details

#needs_help?(params) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/chef-dk/command/base.rb', line 69

def needs_help?(params)
  params.include?("-h") || params.include?("--help")
end

#needs_version?(params) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/chef-dk/command/base.rb', line 73

def needs_version?(params)
  params.include?("-v") || params.include?("--version")
end

#run_with_default_options(params = [ ]) ⇒ Object

optparser overwrites -h / –help options with its own. In order to control this behavior, make sure the default options are handled here.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/chef-dk/command/base.rb', line 50

def run_with_default_options(params = [ ])
  if needs_help?(params)
    msg(opt_parser.to_s)
    0
  elsif needs_version?(params)
    msg("Chef Development Kit Version: #{ChefDK::VERSION}")
    0
  else
    run(params)
  end
rescue Chef::Exceptions::ConfigurationError => e
  err("ERROR: #{e.message}\n")
  1
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
  err("ERROR: #{e.message}\n")
  msg(opt_parser)
  1
end