Class: ChefDK::Command::Base
- Inherits:
-
Object
- Object
- ChefDK::Command::Base
- Includes:
- Helpers, Mixlib::CLI
- Defined in:
- lib/chef-dk/command/base.rb
Direct Known Subclasses
Diff, Env, Exec, Export, GemForwarder, Generate, GeneratorCommands::App, GeneratorCommands::Base, Install, Provision, Push, PushArchive, ShellInit, ShowPolicy, Update, Verify
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #needs_help?(params) ⇒ Boolean
- #needs_version?(params) ⇒ Boolean
-
#run_with_default_options(params = [ ]) ⇒ Object
optparser overwrites -h / –help options with its own.
Methods included from Helpers
#chefdk_home, #err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command
Constructor Details
#initialize ⇒ Base
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
65 66 67 |
# File 'lib/chef-dk/command/base.rb', line 65 def needs_help?(params) params.include?("-h") || params.include?("--help") end |
#needs_version?(params) ⇒ Boolean
69 70 71 |
# File 'lib/chef-dk/command/base.rb', line 69 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 60 61 62 63 |
# File 'lib/chef-dk/command/base.rb', line 49 def (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 OptionParser::InvalidOption => e err(e.) msg(opt_parser) 1 end |