7
7
module PuppetStrings ::Describe
8
8
# Renders requested types or a summarized list in the current YARD registry to STDOUT.
9
9
# @param [Array] describe_types The list of names of the types to be displayed.
10
- # @param [bool] list Create the summarized list instead of describing each type.
11
- # @param [bool] _providers Show details of the providers.
10
+ # @param [bool] list_types Create the summarized list instead of describing each type.
11
+ # @param [bool] show_type_providers Show details of the providers of a specified type.
12
+ # @param [bool] list_providers Create a summarized list of providers.
12
13
# @return [void]
13
- def self . render ( describe_types = [ ] , list = false , _providers = false )
14
+ def self . render ( describe_types = [ ] , list_types = false , show_type_providers = true , list_providers = false )
14
15
document = {
15
16
defined_types : YARD ::Registry . all ( :puppet_defined_type ) . sort_by! ( &:name ) . map! ( &:to_hash ) ,
16
17
resource_types : YARD ::Registry . all ( :puppet_type ) . sort_by! ( &:name ) . map! ( &:to_hash ) ,
17
18
providers : YARD ::Registry . all ( :puppet_provider ) . sort_by! ( &:name ) . map! ( &:to_hash )
18
19
}
19
-
20
- if list
20
+ # if --list flag passed, produce a summarized list of types
21
+ if list_types
21
22
puts 'These are the types known to puppet:'
22
- document [ :resource_types ] . each { |t | list_one_type ( t ) }
23
- else
24
- document [ :providers ] . each { |p | list_one_type ( p ) }
23
+ document [ :resource_types ] . each { |t | list_one ( t ) }
25
24
25
+ # if a type(s) has been passed, show the details of that type(s)
26
+ elsif describe_types
26
27
type_names = { }
27
- describe_types & .each { |name | type_names [ name ] = true }
28
+ describe_types . each { |name | type_names [ name ] = true }
28
29
29
30
document [ :resource_types ] . each do |t |
30
- show_one_type ( t ) if type_names [ t [ :name ] . to_s ]
31
+ show_one_type ( t , show_type_providers ) if type_names [ t [ :name ] . to_s ]
31
32
end
33
+
34
+ # if --providers flag passed, produce a summarized list of providers
35
+ elsif list_providers
36
+ puts 'These are the providers known to puppet:'
37
+ document [ :providers ] . each { |t | list_one ( t ) }
32
38
end
33
39
end
34
40
35
- def self . show_one_type ( resource_type )
41
+ def self . show_one_type ( resource_type , providers = true )
36
42
puts format ( "\n %<name>s\n %<underscore>s" , name : resource_type [ :name ] , underscore : '=' * resource_type [ :name ] . length )
37
43
puts resource_type [ :docstring ] [ :text ]
38
44
@@ -43,8 +49,10 @@ def self.show_one_type(resource_type)
43
49
44
50
puts "\n Parameters\n ----------"
45
51
combined_list . sort_by { |p | p [ :name ] } . each { |p | show_one_parameter ( p ) }
52
+ return unless providers
53
+
46
54
puts "\n Providers\n ---------"
47
- # Show providers here - list or provide details
55
+ resource_type [ :providers ] . sort_by { | p | p [ :name ] } . each { | p | puts p [ :name ] . to_s . ljust ( 15 ) }
48
56
end
49
57
50
58
def self . show_one_parameter ( parameter )
@@ -54,14 +62,14 @@ def self.show_one_parameter(parameter)
54
62
puts format ( 'Requires features %<required_features>s.' , required_features : parameter [ :required_features ] ) unless parameter [ :required_features ] . nil?
55
63
end
56
64
57
- def self . list_one_type ( type )
65
+ def self . list_one ( object )
58
66
targetlength = 48
59
67
shortento = targetlength - 4
60
- contentstring = type [ :docstring ] [ :text ]
68
+ contentstring = object [ :docstring ] [ :text ]
61
69
end_of_line = contentstring . index ( "\n " ) # "." gives closer results to old describeb, but breaks for '.k5login'
62
70
contentstring = contentstring [ 0 ..end_of_line ] unless end_of_line . nil?
63
71
contentstring = "#{ contentstring [ 0 ..shortento ] } ..." if contentstring . length > targetlength
64
72
65
- puts "#{ type [ :name ] . to_s . ljust ( 15 ) } - #{ contentstring } "
73
+ puts "#{ object [ :name ] . to_s . ljust ( 15 ) } - #{ contentstring } "
66
74
end
67
75
end
0 commit comments