Skip to content

Instantly share code, notes, and snippets.

@bobtfish
Created November 10, 2013 20:51
Show Gist options
  • Save bobtfish/7403811 to your computer and use it in GitHub Desktop.
Save bobtfish/7403811 to your computer and use it in GitHub Desktop.
Get docs for the functions you've got in puppet _AND_ your current module set
require 'puppet'
Puppet[:parser] = 'future'
Puppet[:environment] = 'master'
Puppet[:manifest] = 'manifests/site.pp'
Puppet[:modulepath] = 'modules/:vendor/modules/'
Puppet.settings.initialize_app_defaults({
:logdir => "/dev/null",
:confdir => "/dev/null",
:vardir => "/dev/null",
:rundir => "/dev/null",
:hiera_config => "/dev/null",
})
def functiondocs
Puppet::Parser::Functions.autoloader.loadall
data = {}
Puppet::Parser::Functions.send(:merged_functions).each do |name, hash|
ret = "#{name}\n#{"-" * name.to_s.length}\n"
if hash[:doc]
ret << Puppet::Util::Docs.scrub(hash[:doc])
else
ret << "Undocumented.\n"
end
ret << "\n\n- *Type*: #{hash[:type]}\n\n"
data[name.to_s] = ret
end
data
end
func_name = ARGV.first
docs = functiondocs
if func_name
if func_name == 'list'
puts docs.keys.join("\n")
else
if doc = docs[func_name]
puts doc
else
puts "Function #{func_name} not found!"
end
end
else
docs.keys.sort.each do |name|
puts docs[name]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment