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
CleanPolicyCookbooks, CleanPolicyRevisions, DeletePolicy, DeletePolicyGroup, Diff, Env, Exec, Export, GemForwarder, Generate, GeneratorCommands::App, GeneratorCommands::Base, Install, Provision, Push, PushArchive, ShellInit, ShowPolicy, Undelete, 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, #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
#initialize ⇒ Base
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
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
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 (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.}\n") 1 rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e err("ERROR: #{e.}\n") msg(opt_parser) 1 end |