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 <[email protected]>
---
 lib/puppet/application/man.rb |    4 +++
 lib/puppet/face/man.rb        |   47 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 0 deletions(-)
 create mode 100644 lib/puppet/application/man.rb
 create mode 100644 lib/puppet/face/man.rb

diff --git a/lib/puppet/application/man.rb b/lib/puppet/application/man.rb
new file mode 100644
index 0000000..1ecc4d6
--- /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 0000000..44a3394
--- /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
-- 
1.7.5.2

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to