77module PuppetStrings ::Describe
88 # Renders requested types or a summarized list in the current YARD registry to STDOUT.
99 # @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.
1213 # @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 )
1415 document = {
1516 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 )
1719 }
18-
19- if list
20+ # if --list flag passed, produce a summarized list of types
21+ if list_types
2022 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 ) }
2424
25+ # if a type(s) has been passed, show the details of that type(s)
26+ elsif describe_types
2527 type_names = { }
2628 describe_types . each { |name | type_names [ name ] = true }
2729
2830 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 ]
3032 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 ) }
3138 end
3239 end
3340
34- def self . show_one_type ( resource_type )
41+ def self . show_one_type ( resource_type , providers = true )
3542 puts format ( "\n %<name>s\n %<underscore>s" , name : resource_type [ :name ] , underscore : '=' * resource_type [ :name ] . length )
3643 puts resource_type [ :docstring ] [ :text ]
3744
@@ -42,8 +49,10 @@ def self.show_one_type(resource_type)
4249
4350 puts "\n Parameters\n ----------"
4451 combined_list . sort_by { |p | p [ :name ] } . each { |p | show_one_parameter ( p ) }
52+ return unless providers
53+
4554 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 ) }
4756 end
4857
4958 def self . show_one_parameter ( parameter )
@@ -53,14 +62,14 @@ def self.show_one_parameter(parameter)
5362 puts format ( 'Requires features %<required_features>s.' , required_features : parameter [ :required_features ] ) unless parameter [ :required_features ] . nil?
5463 end
5564
56- def self . list_one_type ( type )
65+ def self . list_one ( object )
5766 targetlength = 48
5867 shortento = targetlength - 4
59- contentstring = type [ :docstring ] [ :text ]
68+ contentstring = object [ :docstring ] [ :text ]
6069 end_of_line = contentstring . index ( "\n " ) # "." gives closer results to old describeb, but breaks for '.k5login'
6170 contentstring = contentstring [ 0 ..end_of_line ] unless end_of_line . nil?
6271 contentstring = "#{ contentstring [ 0 ..shortento ] } ..." if contentstring . length > targetlength
6372
64- puts "#{ type [ :name ] . to_s . ljust ( 15 ) } - #{ contentstring } "
73+ puts "#{ object [ :name ] . to_s . ljust ( 15 ) } - #{ contentstring } "
6574 end
6675end
0 commit comments