diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-06 11:08:35 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-06 11:08:35 -0700 |
| commit | f80afbe72b848fe4ed81d8116d4eeb494aa6f61e (patch) | |
| tree | 73c7f27f2ea2fb1668f7067ce05638f5064f540d /lib/puppet/interface.rb | |
| parent | 1b12b55b6a2d3581f9643bf09d55727ba1213580 (diff) | |
| parent | b983386ece1b9816e6d3d59a316ad589e35773df (diff) | |
| download | puppet-f80afbe72b848fe4ed81d8116d4eeb494aa6f61e.tar.gz puppet-f80afbe72b848fe4ed81d8116d4eeb494aa6f61e.tar.xz puppet-f80afbe72b848fe4ed81d8116d4eeb494aa6f61e.zip | |
Merge branch '2.7.x' into 2.7.next
Conflicts:
* spec/unit/node/facts_spec.rb
Updates:
* spec/unit/interface/action{,_builder}_spec.rb
=> update for 'when_invoked' block being required.
Diffstat (limited to 'lib/puppet/interface.rb')
| -rw-r--r-- | lib/puppet/interface.rb | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb index ced00863d..10e2ec8d7 100644 --- a/lib/puppet/interface.rb +++ b/lib/puppet/interface.rb @@ -1,7 +1,11 @@ require 'puppet' require 'puppet/util/autoload' +require 'puppet/interface/documentation' +require 'prettyprint' class Puppet::Interface + include FullDocs + require 'puppet/interface/face_collection' require 'puppet/interface/action_manager' @@ -65,27 +69,33 @@ class Puppet::Interface Puppet.warning("set_default_format is deprecated (and ineffective); use render_as on your actions instead.") end + ######################################################################## # Documentation. We currently have to rewrite both getters because we share # the same instance between build-time and the runtime instance. When that # splits out this should merge into a module that both the action and face # include. --daniel 2011-04-17 - attr_accessor :summary, :description - def summary(value = nil) - self.summary = value unless value.nil? - @summary - end - def summary=(value) - value = value.to_s - value =~ /\n/ and - raise ArgumentError, "Face summary should be a single line; put the long text in 'description' instead." - - @summary = value - end - - def description(value = nil) - self.description = value unless value.nil? - @description + def synopsis + output = PrettyPrint.format do |s| + s.text("puppet #{name} <action>") + s.breakable + + options.each do |option| + option = get_option(option) + wrap = option.required? ? %w{ < > } : %w{ [ ] } + + s.group(0, *wrap) do + option.optparse.each do |item| + unless s.current_group.first? + s.breakable + s.text '|' + s.breakable + end + s.text item + end + end + end + end end @@ -97,9 +107,15 @@ class Puppet::Interface raise ArgumentError, "Cannot create face #{name.inspect} with invalid version number '#{version}'!" end - @name = Puppet::Interface::FaceCollection.underscorize(name) + @name = Puppet::Interface::FaceCollection.underscorize(name) @version = version + # The few bits of documentation we actually demand. The default license + # is a favour to our end users; if you happen to get that in a core face + # report it as a bug, please. --daniel 2011-04-26 + @authors = [] + @license = 'All Rights Reserved' + instance_eval(&block) if block_given? end @@ -139,12 +155,12 @@ class Puppet::Interface action.get_option(name).__decoration_name(type) end + methods.reverse! if type == :after + + # Exceptions here should propagate up; this implements a hook we can use + # reasonably for option validation. methods.each do |hook| - begin - respond_to? hook and self.__send__(hook, action, passed_args, passed_options) - rescue => e - Puppet.warning("invoking #{action} #{type} hook: #{e}") - end + respond_to? hook and self.__send__(hook, action, passed_args, passed_options) end end |
