From 2389bdf85bf0ae26110666ff34680d057acc32ff Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Wed, 1 Jun 2011 14:17:11 -0700 Subject: (#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 --- lib/puppet/application/man.rb | 4 ++++ lib/puppet/face/man.rb | 47 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 lib/puppet/application/man.rb create mode 100644 lib/puppet/face/man.rb (limited to 'lib/puppet') 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 "" + 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 -- cgit