summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface/action.rb
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-27 12:12:05 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-27 12:12:05 -0700
commitebf49f98357f93b33e09c0ecbdee1c5c2db87569 (patch)
tree8500c7f7c87ca5f32f22a70fde97b738c0427f54 /lib/puppet/interface/action.rb
parent1aaf5fdc51e165c7d0f377450016cd4fb3767c02 (diff)
parent0256d67e1a51a37f2c87ec197bdff6ef3a6b269f (diff)
downloadpuppet-ebf49f98357f93b33e09c0ecbdee1c5c2db87569.tar.gz
puppet-ebf49f98357f93b33e09c0ecbdee1c5c2db87569.tar.xz
puppet-ebf49f98357f93b33e09c0ecbdee1c5c2db87569.zip
Merge branch 'feature/2.7.x/6962-finish-documentation-api-for-faces' into 2.7.x
Diffstat (limited to 'lib/puppet/interface/action.rb')
-rw-r--r--lib/puppet/interface/action.rb52
1 files changed, 36 insertions, 16 deletions
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index 464b2a738..ac66d2946 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -1,12 +1,21 @@
-# -*- coding: utf-8 -*-
require 'puppet/interface'
-require 'puppet/interface/option'
+require 'puppet/interface/documentation'
+require 'prettyprint'
class Puppet::Interface::Action
+ include Puppet::Interface::FullDocs
+
def initialize(face, name, attrs = {})
raise "#{name.inspect} is an invalid action name" unless name.to_s =~ /^[a-z]\w*$/
@face = face
@name = name.to_sym
+
+ # 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'
+
attrs.each do |k, v| send("#{k}=", v) end
@options = {}
@@ -30,8 +39,31 @@ class Puppet::Interface::Action
!!@default
end
- attr_accessor :summary
-
+ ########################################################################
+ # Documentation...
+ def synopsis
+ output = PrettyPrint.format do |s|
+ s.text("puppet #{@face.name}")
+ s.text(" #{name}") unless default?
+ 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
########################################################################
# Support for rendering formats and all.
@@ -83,18 +115,6 @@ class Puppet::Interface::Action
########################################################################
- # Documentation stuff, whee!
- attr_accessor :summary, :description
- 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
-
-
- ########################################################################
# Initially, this was defined to allow the @action.invoke pattern, which is
# a very natural way to invoke behaviour given our introspection
# capabilities. Heck, our initial plan was to have the faces delegate to