summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-11 16:47:16 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-12 16:12:09 -0700
commitec988e24ce3713a4c4a31918489136f88b6945e6 (patch)
treee2d2850d9094fbd9dc005740abe1bba05041a325 /lib/puppet
parent2a87f410eae84a0a7c4f39d9c1ef742c3e7ba8fc (diff)
downloadpuppet-ec988e24ce3713a4c4a31918489136f88b6945e6.tar.gz
puppet-ec988e24ce3713a4c4a31918489136f88b6945e6.tar.xz
puppet-ec988e24ce3713a4c4a31918489136f88b6945e6.zip
(#6962) Move the logic for help layout into erb templates.
Rather than hard-coding the layout of help output in the code, push it out into external templates. At the moment overriding that would require changing the ERB code next to puppet/faces/help.rb file on disk. Paired-With: Matt Robinson <matt@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/faces/help.rb60
-rw-r--r--lib/puppet/faces/help/action.erb3
-rw-r--r--lib/puppet/faces/help/face.erb7
-rw-r--r--lib/puppet/faces/help/global.erb20
4 files changed, 44 insertions, 46 deletions
diff --git a/lib/puppet/faces/help.rb b/lib/puppet/faces/help.rb
index 17ce3ec6b..c5f4b0fe6 100644
--- a/lib/puppet/faces/help.rb
+++ b/lib/puppet/faces/help.rb
@@ -1,9 +1,9 @@
require 'puppet/faces'
require 'puppet/util/command_line'
+require 'pathname'
+require 'erb'
Puppet::Faces.define(:help, '0.0.1') do
- HelpSummaryFormat = ' %-18s %s'
-
summary "Displays help about puppet subcommands"
action(:help) do
@@ -38,54 +38,22 @@ Puppet::Faces.define(:help, '0.0.1') do
face = facename ? Puppet::Faces[facename.to_sym, version] : nil
action = (face and actionname) ? face.get_action(actionname.to_sym) : nil
- # Finally, build up the help text. Maybe ERB would have been nicer
- # after all. Oh, well. --daniel 2011-04-11
- message = []
- if args.length == 0 then
- message << "Use: puppet <subcommand> [options] <action> [options]"
- message << ""
- message << "Available subcommands, from Puppet Faces:"
- Puppet::Faces.faces.sort.each do |name|
- face = Puppet::Faces[name, :current]
- message << format(HelpSummaryFormat, face.name, face.summary)
- end
-
- unless legacy_applications.empty? then # great victory when this is true!
- message << ""
- message << "Available applications, soon to be ported to Faces:"
- legacy_applications.each do |appname|
- summary = horribly_extract_summary_from appname
- message << format(HelpSummaryFormat, appname, summary)
- end
- end
-
- message << ""
- message << <<EOT.split("\n")
-See 'puppet help <subcommand> <action>' for help on a specific subcommand action.
-See 'puppet help <subcommand>' for help on a specific subcommand.
-See 'puppet man <subcommand>' for the full man page.
-Puppet v#{Puppet::PUPPETVERSION}
-EOT
- elsif args.length == 1 then
- message << "Use: puppet #{face.name} [options] <action> [options]"
- message << ""
+ template = case args.length
+ when 0 then erb_template 'global.erb'
+ when 1 then erb_template 'face.erb'
+ when 2 then erb_template 'action.erb'
+ else
+ fail ArgumentError, "Too many arguments to help action"
+ end
- message << "Available actions:"
- face.actions.each do |actionname|
- action = face.get_action(actionname)
- message << format(HelpSummaryFormat, action.name, action.summary)
- end
-
- elsif args.length == 2
- "REVISIT: gotta write this code."
- else
- raise ArgumentError, "help only takes two arguments, a face name and an action"
- end
-
- message
+ return ERB.new(template, nil, '%').result(binding)
end
end
+ def erb_template(name)
+ (Pathname(__FILE__).dirname + "help" + name).read
+ end
+
def legacy_applications
# The list of applications, less those that are duplicated as a face.
Puppet::Util::CommandLine.available_subcommands.reject do |appname|
diff --git a/lib/puppet/faces/help/action.erb b/lib/puppet/faces/help/action.erb
new file mode 100644
index 000000000..eaf131464
--- /dev/null
+++ b/lib/puppet/faces/help/action.erb
@@ -0,0 +1,3 @@
+Use: puppet <%= face.name %> [options] <%= action.name %> [options]
+
+Summary: <%= action.summary %>
diff --git a/lib/puppet/faces/help/face.erb b/lib/puppet/faces/help/face.erb
new file mode 100644
index 000000000..efe5fd809
--- /dev/null
+++ b/lib/puppet/faces/help/face.erb
@@ -0,0 +1,7 @@
+Use: puppet <%= face.name %> [options] <action> [options]
+
+Available actions:
+% face.actions.each do |actionname|
+% action = face.get_action(actionname)
+ <%= action.name.to_s.ljust(16) %> <%= action.summary %>
+% end
diff --git a/lib/puppet/faces/help/global.erb b/lib/puppet/faces/help/global.erb
new file mode 100644
index 000000000..e123367a2
--- /dev/null
+++ b/lib/puppet/faces/help/global.erb
@@ -0,0 +1,20 @@
+puppet <subcommand> [options] <action> [options]
+
+Available subcommands, from Puppet Faces:
+% Puppet::Faces.faces.sort.each do |name|
+% face = Puppet::Faces[name, :current]
+ <%= face.name.to_s.ljust(16) %> <%= face.summary %>
+% end
+
+% unless legacy_applications.empty? then # great victory when this is true!
+Available applications, soon to be ported to Faces:
+% legacy_applications.each do |appname|
+% summary = horribly_extract_summary_from appname
+ <%= appname.to_s.ljust(16) %> <%= summary %>
+% end
+% end
+
+See 'puppet help <subcommand> <action>' for help on a specific subcommand action.
+See 'puppet help <subcommand>' for help on a specific subcommand.
+See 'puppet man <subcommand>' for the full man page.
+Puppet v<%= Puppet::PUPPETVERSION %>