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 ) ,
1617 resource_types : YARD ::Registry . all ( :puppet_type ) . sort_by! ( &:name ) . map! ( &:to_hash ) ,
1718 providers : YARD ::Registry . all ( :puppet_provider ) . sort_by! ( &:name ) . map! ( &:to_hash )
1819 }
19-
20- if list
20+ # if --list flag passed, produce a summarized list of types
21+ if list_types
2122 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 ) }
2524
25+ # if a type(s) has been passed, show the details of that type(s)
26+ elsif describe_types
2627 type_names = { }
27- describe_types & .each { |name | type_names [ name ] = true }
28+ describe_types . each { |name | type_names [ name ] = true }
2829
2930 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 ]
3132 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 ) }
3238 end
3339 end
3440
35- def self . show_one_type ( resource_type )
41+ def self . show_one_type ( resource_type , providers = true )
3642 puts format ( "\n %<name>s\n %<underscore>s" , name : resource_type [ :name ] , underscore : '=' * resource_type [ :name ] . length )
3743 puts resource_type [ :docstring ] [ :text ]
3844
@@ -43,8 +49,10 @@ def self.show_one_type(resource_type)
4349
4450 puts "\n Parameters\n ----------"
4551 combined_list . sort_by { |p | p [ :name ] } . each { |p | show_one_parameter ( p ) }
52+ return unless providers
53+
4654 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 ) }
4856 end
4957
5058 def self . show_one_parameter ( parameter )
@@ -54,14 +62,14 @@ def self.show_one_parameter(parameter)
5462 puts format ( 'Requires features %<required_features>s.' , required_features : parameter [ :required_features ] ) unless parameter [ :required_features ] . nil?
5563 end
5664
57- def self . list_one_type ( type )
65+ def self . list_one ( object )
5866 targetlength = 48
5967 shortento = targetlength - 4
60- contentstring = type [ :docstring ] [ :text ]
68+ contentstring = object [ :docstring ] [ :text ]
6169 end_of_line = contentstring . index ( "\n " ) # "." gives closer results to old describeb, but breaks for '.k5login'
6270 contentstring = contentstring [ 0 ..end_of_line ] unless end_of_line . nil?
6371 contentstring = "#{ contentstring [ 0 ..shortento ] } ..." if contentstring . length > targetlength
6472
65- puts "#{ type [ :name ] . to_s . ljust ( 15 ) } - #{ contentstring } "
73+ puts "#{ object [ :name ] . to_s . ljust ( 15 ) } - #{ contentstring } "
6674 end
6775end
0 commit comments