41
# Copyright (c) 2005 Reductive Labs, LLC
44
# Copyright (c) 2005-2007 Reductive Labs, LLC
42
45
# Licensed under the GNU Public License
48
require 'puppet/util/reference'
49
require 'puppet/network/handler'
45
50
require 'getoptlong'
47
52
result = GetoptLong.new(
53
[ "--all", "-a", GetoptLong::NO_ARGUMENT ],
54
[ "--list", "-l", GetoptLong::NO_ARGUMENT ],
55
[ "--format", "-f", GetoptLong::REQUIRED_ARGUMENT ],
48
56
[ "--mode", "-m", GetoptLong::REQUIRED_ARGUMENT ],
57
[ "--reference", "-r", GetoptLong::REQUIRED_ARGUMENT ],
49
58
[ "--help", "-h", GetoptLong::NO_ARGUMENT ]
64
options = {:references => [], :mode => :text, :format => :to_rest}
66
Reference = Puppet::Util::Reference
59
69
result.each { |opt,arg|
64
if Puppet.feature.usage?
67
puts "No help available unless you have RDoc::usage installed"
74
method = "to_%s" % arg
75
if Reference.method_defined?(method)
76
options[:format] = method
78
raise "Invalid output format %s" % arg
81
if Reference.modes.include?(arg)
82
options[:mode] = arg.intern
84
raise "Invalid output mode %s" % arg
87
puts Reference.references.collect { |r| Reference.reference(r).doc }.join("\n")
90
options[:references] << arg.intern
92
if Puppet.features.usage?
95
puts "No help available unless you have RDoc::usage installed"
72
100
rescue GetoptLong::InvalidOption => detail
77
include Puppet::Util::Docs
79
# Indent every line in the chunk except those which begin with '..'.
81
return text.gsub(/(^|\A)/, tab).gsub(/^ +\.\./, "..")
84
def paramwrap(name, text, namevar = false)
86
name = name.to_s + " (*namevar*)"
95
# Print the docs for arguments
98
Puppet.config.each do |name, object|
103
a[0].to_s <=> b[0].to_s
104
}.each do |name, object|
105
# Make each name an anchor
106
puts %{#### <a name="#{name.to_s}">#{name.to_s}</a> (<em>#{object.section.to_s}</em>)}
110
if val = object.value and val != ""
111
default = " ``%s``" % val
106
# Don't add dynamic references to the "all" list.
107
options[:references] = Reference.references.reject do |ref|
108
Reference.reference(ref).dynamic?
112
if options[:references].empty?
113
options[:references] << :type
118
options[:references].each do |name|
119
section = Puppet::Util::Reference.reference(name) or raise "Could not find section %s" % name
120
unless options[:mode] == :pdf
126
if options[:references].length > 1
127
with_contents = false
132
options[:references].sort { |a,b| a.to_s <=> b.to_s }.each do |name|
133
raise "Could not find reference %s" % name unless section = Puppet::Util::Reference.reference(name)
114
puts object.desc.gsub(/\n/, " ") + default
136
# Add the per-section text, but with no ToC
137
text += section.send(options[:format], with_contents)
116
139
puts detail.backtrace
140
$stderr.puts "Could not generate reference %s: %s" % [name, detail]
124
# Print the docs for types
129
Puppet::Type.eachtype { |type|
130
next if type.name == :puppet
131
next if type.name == :component
132
types[type.name] = type
136
puts "## Table of Contents"
137
puts "1. <a href='#meta-parameters'>Meta-Parameters</a>"
138
types.sort { |a, b| a[0].to_s <=> b[0].to_s }.each do |name, type|
139
puts "1. <a href='#%s'>%s</a>" % [type.name, type.name.to_s.capitalize]
143
<h2><a name="meta-parameters">Meta-Parameters</a></h2>
145
Metaparameters are parameters that work with any element; they are part of the
146
Puppet framework itself rather than being part of the implementation of any
147
given instance. Thus, any defined metaparameter can be used with any instance
148
in your manifest, including defined components.
153
Puppet::Type.eachmetaparam { |param|
160
paramwrap(param.to_s, scrub(Puppet::Type.metaparamdoc(param)))
161
#puts "<dt>" + param.to_s + "</dt>"
162
#puts tab(1) + Puppet::Type.metaparamdoc(param).scrub.indent($tab)gsub(/\n\s*/,' ')
164
#puts indent(scrub(Puppet::Type.metaparamdoc(param)), $tab)
165
#puts scrub(Puppet::Type.metaparamdoc(param))
171
puts detail.backtrace
172
puts "incorrect metaparams: %s" % detail
179
- *namevar* is the parameter used to uniquely identify a type instance.
180
This is the parameter that gets assigned when a string is provided before
181
the colon in a type declaration. In general, only developers will need to
182
worry about which parameter is the ``namevar``.
184
In the following code:
186
file { "/etc/passwd":
192
"/etc/passwd" is considered the name of the file object (used for things like
193
dependency handling), and because ``path`` is the namevar for ``file``, that
194
string is assigned to the ``path`` parameter.
196
- *parameters* determine the specific configuration of the instance. They either
197
directly modify the system (internally, these are called states) or they affect
198
how the instance behaves (e.g., adding a search path for ``exec`` instances
199
or determining recursion on ``file`` instances).
201
When required binaries are specified for providers, fully qualifed paths
202
indicate that the binary must exist at that specific path and unqualified
203
binaries indicate that Puppet will search for the binary using the shell
219
<h2><a name='%s'>%s</a></h2>" % [name, name]
220
puts scrub(type.doc) + "\n\n"
223
type.validstates.sort { |a,b|
226
state = type.statebyname(sname)
229
state = type.statebyname(sname)
232
raise "Could not retrieve state %s on type %s" % [sname, type.name]
237
unless doc = state.doc
238
$stderr.puts "No docs for %s[%s]" % [type, sname]
245
#str = indent(str, $tab)
249
puts "\n### %s Parameters\n" % name.to_s.capitalize
250
type.parameters.sort { |a,b|
252
}.each { |name,param|
253
#docs[name] = indent(scrub(type.paramdoc(name)), $tab)
254
docs[name] = scrub(type.paramdoc(name))
258
a[0].to_s <=> b[0].to_s
260
namevar = type.namevar == name and name != :name
261
paramwrap(name, doc, namevar)
268
puts Puppet::Server::Report.reportdocs
272
puts Puppet::Parser::Functions.functiondocs
275
unless respond_to?(mode)
276
raise "Invalid mode %s" % mode
286
puts "\n*This page autogenerated on %s*" % Time.now
288
# $Id: puppetdoc 1846 2006-11-09 21:25:02Z luke $
146
unless with_contents # We've only got one reference
147
text += Puppet::Util::Reference.footer
150
# Replace the trac links, since they're invalid everywhere else
151
text.gsub!(/`\w+\s+([^`]+)`:trac:/) { |m| $1 }
153
if options[:mode] == :pdf
154
Puppet::Util::Reference.pdf(text)