summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-06-01 14:17:11 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-06-01 16:28:15 -0700
commit2389bdf85bf0ae26110666ff34680d057acc32ff (patch)
tree2bd490ec3a945cdf5137d8491ae2a91502793950 /lib/puppet
parente647f70cbde1735af0710d07fc704448f5a8dcd8 (diff)
downloadpuppet-2389bdf85bf0ae26110666ff34680d057acc32ff.tar.gz
puppet-2389bdf85bf0ae26110666ff34680d057acc32ff.tar.xz
puppet-2389bdf85bf0ae26110666ff34680d057acc32ff.zip
(#7683) Add a 'man' face and subcommand to Puppet.
This is the minimal wrapper, cloning a good deal of the logic from help, that runs our face through the 'man' template and returns ronn-formatted Markdown. This provides the crudest baseline possible for getting man-style output, but lets us move forward to improve behaviour. Reviewed-By: Nick Fagerlund <nick.fagerlund@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/application/man.rb4
-rw-r--r--lib/puppet/face/man.rb47
2 files changed, 51 insertions, 0 deletions
diff --git a/lib/puppet/application/man.rb b/lib/puppet/application/man.rb
new file mode 100644
index 000000000..1ecc4d691
--- /dev/null
+++ b/lib/puppet/application/man.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/face_base'
+
+class Puppet::Application::Man < Puppet::Application::FaceBase
+end
diff --git a/lib/puppet/face/man.rb b/lib/puppet/face/man.rb
new file mode 100644
index 000000000..44a339490
--- /dev/null
+++ b/lib/puppet/face/man.rb
@@ -0,0 +1,47 @@
+require 'puppet/face'
+require 'pathname'
+require 'erb'
+
+Puppet::Face.define(:man, '0.0.1') do
+ copyright "Puppet Labs", 2011
+ license "Apache 2 license; see COPYING"
+
+ summary "Display Puppet subcommand manual pages."
+
+ action(:man) do
+ summary "Display the manual page for a face."
+ arguments "<face>"
+ returns "The man data, in markdown format, suitable for consumption by Ronn."
+ examples <<-'EOT'
+ Get the manual page for a face:
+
+ $ puppet man facts
+ EOT
+
+ default
+ when_invoked do |name, options|
+ if legacy_applications.include? name then
+ return Puppet::Application[name].help
+ end
+
+ face = Puppet::Face[name.to_sym, :current]
+
+ file = (Pathname(__FILE__).dirname + "help" + 'man.erb')
+ erb = ERB.new(file.read, nil, '-')
+ erb.filename = file.to_s
+
+ # Run the ERB template in our current binding, including all the local
+ # variables we established just above. --daniel 2011-04-11
+ return erb.result(binding)
+ end
+ end
+
+ def legacy_applications
+ # The list of applications, less those that are duplicated as a face.
+ Puppet::Util::CommandLine.available_subcommands.reject do |appname|
+ Puppet::Face.face? appname.to_sym, :current or
+ # ...this is a nasty way to exclude non-applications. :(
+ %w{face_base indirection_base}.include? appname
+ end
+ end
+end