Class: TypeDoc

Inherits:
Object show all
Defined in:
lib/puppet/application/describe.rb

Instance Method Summary collapse

Constructor Details

#initializeTypeDoc

Returns a new instance of TypeDoc.



55
56
57
58
59
60
61
62
63
64
# File 'lib/puppet/application/describe.rb', line 55

def initialize
  @format = Formatter.new(76)
  @types = {}
  Puppet::Type.loadall
  Puppet::Type.eachtype { |type|
    next if type.name == :component

    @types[type.name] = type
  }
end

Instance Method Details

#format_attrs(type, attrs) ⇒ Object

List details about attributes



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/puppet/application/describe.rb', line 122

def format_attrs(type, attrs)
  docs = {}
  type.allattrs.each do |name|
    kind = type.attrtype(name)
    docs[name] = type.attrclass(name).doc if attrs.include?(kind) && name != :provider
  end

  docs.sort { |a,b|
    a[0].to_s <=> b[0].to_s
  }.each { |name, doc|
    print "\n- **#{name}**"
    if type.key_attributes.include?(name) and name != :name
      puts " (*namevar*)"
    else
      puts ""
    end
    puts @format.wrap(doc, :indent => 4, :scrub => true)
  }
end

#format_providers(type) ⇒ Object



152
153
154
155
156
157
# File 'lib/puppet/application/describe.rb', line 152

def format_providers(type)
  type.providers.sort_by(&:to_s).each { |prov|
    puts "\n- **#{prov}**"
    puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true)
  }
end

#format_type(name, opts) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/puppet/application/describe.rb', line 85

def format_type(name, opts)
  name = name.to_sym
  unless @types.has_key?(name)
    puts "Unknown type #{name}"
    return
  end
  type = @types[name]
  puts @format.header(name.to_s, "=")
  puts @format.wrap(type.doc, :indent => 0, :scrub => true) + "\n\n"

  puts @format.header("Parameters")
  if opts[:parameters]
    format_attrs(type, [:property, :param])
  else
    list_attrs(type, [:property, :param])
  end

  if opts[:meta]
    puts @format.header("Meta Parameters")
    if opts[:parameters]
      format_attrs(type, [:meta])
    else
      list_attrs(type, [:meta])
    end
  end

  if type.providers.size > 0
    puts @format.header("Providers")
    if opts[:providers]
      format_providers(type)
    else
      list_providers(type)
    end
  end
end

#list_attrs(type, attrs) ⇒ Object

List the names of attributes



143
144
145
146
147
148
149
150
# File 'lib/puppet/application/describe.rb', line 143

def list_attrs(type, attrs)
  params = []
  type.allattrs.each do |name|
    kind = type.attrtype(name)
    params << name.to_s if attrs.include?(kind) && name != :provider
  end
  puts @format.wrap(params.sort.join(", "), :indent => 4)
end

#list_providers(type) ⇒ Object



159
160
161
162
# File 'lib/puppet/application/describe.rb', line 159

def list_providers(type)
  list = type.providers.sort_by(&:to_s).join(", ")
  puts @format.wrap(list, :indent => 4)
end

#list_typesObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/puppet/application/describe.rb', line 66

def list_types
  puts "These are the types known to puppet:\n"
  @types.keys.sort_by(&:to_s).each do |name|
    type = @types[name]
    s = type.doc.gsub(/\s+/, " ")
    if s.empty?
      s = ".. no documentation .."
    else
      n = s.index(".") || s.length
      if n > 45
        s = s[0, 45] + " ..."
      else
        s = s[0, n]
      end
    end
    printf "%-15s - %s\n", name, s
  end
end