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