summaryrefslogtreecommitdiffstats
path: root/lib/puppet/application
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-12 16:14:02 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-12 16:14:02 -0700
commit40adee4ade3a447a7397a71d76e042091bbbfbff (patch)
treebb169ff744c7a10772a55770ef976ce4f0e82763 /lib/puppet/application
parent8778307ca33a637fe10b601ee737628f2e5f9fbf (diff)
parent7b4d9367b391f75983868046d30928ebc8411f50 (diff)
downloadpuppet-40adee4ade3a447a7397a71d76e042091bbbfbff.tar.gz
puppet-40adee4ade3a447a7397a71d76e042091bbbfbff.tar.xz
puppet-40adee4ade3a447a7397a71d76e042091bbbfbff.zip
Merge branch 'feature/next/6962-self-documenting-strings-actions-and-options' into next
Diffstat (limited to 'lib/puppet/application')
-rw-r--r--lib/puppet/application/cert.rb3
-rw-r--r--lib/puppet/application/faces_base.rb18
-rw-r--r--lib/puppet/application/help.rb8
3 files changed, 22 insertions, 7 deletions
diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb
index cbd6fd610..c08775380 100644
--- a/lib/puppet/application/cert.rb
+++ b/lib/puppet/application/cert.rb
@@ -48,7 +48,7 @@ class Puppet::Application::Cert < Puppet::Application
end
def help
- puts <<-HELP
+ <<-HELP
puppet-cert(8) -- Manage certificates and requests
========
@@ -166,7 +166,6 @@ COPYRIGHT
Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
HELP
- exit
end
def main
diff --git a/lib/puppet/application/faces_base.rb b/lib/puppet/application/faces_base.rb
index 288b50048..f1b77f285 100644
--- a/lib/puppet/application/faces_base.rb
+++ b/lib/puppet/application/faces_base.rb
@@ -1,5 +1,6 @@
require 'puppet/application'
require 'puppet/faces'
+require 'optparse'
class Puppet::Application::FacesBase < Puppet::Application
should_parse_config
@@ -50,11 +51,13 @@ class Puppet::Application::FacesBase < Puppet::Application
$stderr.puts "Cancelling Face"
exit(0)
end
+ end
+ def parse_options
# We need to parse enough of the command line out early, to identify what
# the action is, so that we can obtain the full set of options to parse.
- # TODO: These should be configurable versions, through a global
+ # REVISIT: These should be configurable versions, through a global
# '--version' option, but we don't implement that yet... --daniel 2011-03-29
@type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym
@face = Puppet::Faces[@type, :current]
@@ -88,25 +91,30 @@ class Puppet::Application::FacesBase < Puppet::Application
index += 1 # ...so skip the argument.
end
else
- raise ArgumentError, "Unknown option #{item.sub(/=.*$/, '').inspect}"
+ raise OptionParser::InvalidOption.new(item.sub(/=.*$/, ''))
end
else
action = @face.get_action(item.to_sym)
if action.nil? then
- raise ArgumentError, "#{@face} does not have an #{item.inspect} action!"
+ raise OptionParser::InvalidArgument.new("#{@face} does not have an #{item} action")
end
@action = action
end
end
- @action or raise ArgumentError, "No action given on the command line!"
+ unless @action
+ raise OptionParser::MissingArgument.new("No action given on the command line")
+ end
- # Finally, we can interact with the default option code to build behaviour
+ # Now we can interact with the default option code to build behaviour
# around the full set of options we now know we support.
@action.options.each do |option|
option = @action.get_option(option) # make it the object.
self.class.option(*option.optparse) # ...and make the CLI parse it.
end
+
+ # ...and invoke our parent to parse all the command line options.
+ super
end
def find_global_settings_argument(item)
diff --git a/lib/puppet/application/help.rb b/lib/puppet/application/help.rb
new file mode 100644
index 000000000..fd8818db0
--- /dev/null
+++ b/lib/puppet/application/help.rb
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+require 'puppet/application/faces_base'
+
+class Puppet::Application::Help < Puppet::Application::FacesBase
+ # Meh. Disable the default behaviour, which is to inspect the
+ # string and return that – not so helpful. --daniel 2011-04-11
+ def render(result) result end
+end