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

#err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_root, #stderr, #stdout, #system_command

Constructor Details

#initializeBase

Returns a new instance of Base.



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

def initialize
  super
end

Instance Method Details

#needs_help?(params) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/chef-dk/command/base.rb', line 61

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

#needs_version?(params) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/chef-dk/command/base.rb', line 65

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.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chef-dk/command/base.rb', line 49

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
end