[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Daniel Pittman
daniel at puppetlabs.com
Tue May 10 08:13:24 UTC 2011
The following commit has been merged in the experimental branch:
commit ec988e24ce3713a4c4a31918489136f88b6945e6
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Mon Apr 11 16:47:16 2011 -0700
(#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 at puppetlabs.com>
diff --git a/lib/puppet/faces/help.rb b/lib/puppet/faces/help.rb
index 17ce3ec..c5f4b0f 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 0000000..eaf1314
--- /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 0000000..efe5fd8
--- /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 0000000..e123367
--- /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 %>
diff --git a/spec/unit/faces/help_spec.rb b/spec/unit/faces/help_spec.rb
index 61f1947..1399abf 100644
--- a/spec/unit/faces/help_spec.rb
+++ b/spec/unit/faces/help_spec.rb
@@ -100,6 +100,4 @@ describe Puppet::Faces[:help, '0.0.1'] do
end
end
end
-
-
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list