pdk 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1329 -1321
  3. data/LICENSE +201 -201
  4. data/README.md +163 -163
  5. data/exe/pdk +10 -10
  6. data/lib/pdk/analytics/client/google_analytics.rb +143 -143
  7. data/lib/pdk/analytics/client/noop.rb +25 -25
  8. data/lib/pdk/analytics/util.rb +19 -19
  9. data/lib/pdk/analytics.rb +30 -30
  10. data/lib/pdk/answer_file.rb +12 -12
  11. data/lib/pdk/bolt.rb +19 -19
  12. data/lib/pdk/cli/build.rb +82 -82
  13. data/lib/pdk/cli/bundle.rb +48 -48
  14. data/lib/pdk/cli/config/get.rb +26 -26
  15. data/lib/pdk/cli/config.rb +22 -22
  16. data/lib/pdk/cli/console.rb +148 -148
  17. data/lib/pdk/cli/convert.rb +52 -52
  18. data/lib/pdk/cli/env.rb +52 -52
  19. data/lib/pdk/cli/errors.rb +25 -25
  20. data/lib/pdk/cli/exec/command.rb +293 -293
  21. data/lib/pdk/cli/exec/interactive_command.rb +114 -114
  22. data/lib/pdk/cli/exec.rb +84 -84
  23. data/lib/pdk/cli/exec_group.rb +104 -104
  24. data/lib/pdk/cli/get/config.rb +24 -24
  25. data/lib/pdk/cli/get.rb +20 -20
  26. data/lib/pdk/cli/module/build.rb +12 -12
  27. data/lib/pdk/cli/module/generate.rb +47 -47
  28. data/lib/pdk/cli/module.rb +14 -14
  29. data/lib/pdk/cli/new/class.rb +32 -32
  30. data/lib/pdk/cli/new/defined_type.rb +32 -32
  31. data/lib/pdk/cli/new/fact.rb +29 -29
  32. data/lib/pdk/cli/new/function.rb +29 -29
  33. data/lib/pdk/cli/new/module.rb +53 -53
  34. data/lib/pdk/cli/new/provider.rb +29 -29
  35. data/lib/pdk/cli/new/task.rb +34 -34
  36. data/lib/pdk/cli/new/test.rb +52 -52
  37. data/lib/pdk/cli/new/transport.rb +27 -27
  38. data/lib/pdk/cli/new.rb +21 -21
  39. data/lib/pdk/cli/release/prep.rb +39 -39
  40. data/lib/pdk/cli/release/publish.rb +50 -50
  41. data/lib/pdk/cli/release.rb +194 -194
  42. data/lib/pdk/cli/remove/config.rb +80 -80
  43. data/lib/pdk/cli/remove.rb +20 -20
  44. data/lib/pdk/cli/set/config.rb +119 -119
  45. data/lib/pdk/cli/set.rb +20 -20
  46. data/lib/pdk/cli/test/unit.rb +90 -90
  47. data/lib/pdk/cli/test.rb +11 -11
  48. data/lib/pdk/cli/update.rb +64 -64
  49. data/lib/pdk/cli/util/command_redirector.rb +27 -27
  50. data/lib/pdk/cli/util/interview.rb +72 -72
  51. data/lib/pdk/cli/util/option_normalizer.rb +55 -55
  52. data/lib/pdk/cli/util/option_validator.rb +68 -68
  53. data/lib/pdk/cli/util/spinner.rb +13 -13
  54. data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
  55. data/lib/pdk/cli/util.rb +305 -305
  56. data/lib/pdk/cli/validate.rb +116 -116
  57. data/lib/pdk/cli.rb +175 -175
  58. data/lib/pdk/config/analytics_schema.json +26 -26
  59. data/lib/pdk/config/errors.rb +5 -5
  60. data/lib/pdk/config/ini_file.rb +183 -183
  61. data/lib/pdk/config/ini_file_setting.rb +39 -39
  62. data/lib/pdk/config/json.rb +34 -34
  63. data/lib/pdk/config/json_schema_namespace.rb +142 -142
  64. data/lib/pdk/config/json_schema_setting.rb +53 -53
  65. data/lib/pdk/config/json_with_schema.rb +49 -49
  66. data/lib/pdk/config/namespace.rb +354 -354
  67. data/lib/pdk/config/setting.rb +135 -135
  68. data/lib/pdk/config/validator.rb +31 -31
  69. data/lib/pdk/config/yaml.rb +46 -46
  70. data/lib/pdk/config/yaml_with_schema.rb +59 -59
  71. data/lib/pdk/config.rb +390 -390
  72. data/lib/pdk/context/control_repo.rb +60 -60
  73. data/lib/pdk/context/module.rb +28 -28
  74. data/lib/pdk/context/none.rb +22 -22
  75. data/lib/pdk/context.rb +99 -99
  76. data/lib/pdk/control_repo.rb +90 -90
  77. data/lib/pdk/generate/defined_type.rb +43 -43
  78. data/lib/pdk/generate/fact.rb +25 -25
  79. data/lib/pdk/generate/function.rb +48 -48
  80. data/lib/pdk/generate/module.rb +352 -352
  81. data/lib/pdk/generate/provider.rb +28 -28
  82. data/lib/pdk/generate/puppet_class.rb +43 -43
  83. data/lib/pdk/generate/puppet_object.rb +232 -232
  84. data/lib/pdk/generate/task.rb +68 -68
  85. data/lib/pdk/generate/transport.rb +33 -33
  86. data/lib/pdk/generate.rb +24 -24
  87. data/lib/pdk/i18n.rb +4 -4
  88. data/lib/pdk/logger.rb +45 -45
  89. data/lib/pdk/module/build.rb +322 -322
  90. data/lib/pdk/module/convert.rb +296 -296
  91. data/lib/pdk/module/metadata.rb +202 -202
  92. data/lib/pdk/module/release.rb +260 -260
  93. data/lib/pdk/module/update.rb +131 -131
  94. data/lib/pdk/module/update_manager.rb +227 -227
  95. data/lib/pdk/module.rb +30 -30
  96. data/lib/pdk/report/event.rb +370 -370
  97. data/lib/pdk/report.rb +121 -121
  98. data/lib/pdk/template/fetcher/git.rb +85 -85
  99. data/lib/pdk/template/fetcher/local.rb +28 -28
  100. data/lib/pdk/template/fetcher.rb +98 -98
  101. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
  102. data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
  103. data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
  104. data/lib/pdk/template/renderer/v1.rb +25 -25
  105. data/lib/pdk/template/renderer.rb +96 -96
  106. data/lib/pdk/template/template_dir.rb +67 -67
  107. data/lib/pdk/template.rb +59 -59
  108. data/lib/pdk/tests/unit.rb +252 -252
  109. data/lib/pdk/util/bundler.rb +259 -259
  110. data/lib/pdk/util/changelog_generator.rb +137 -137
  111. data/lib/pdk/util/env.rb +47 -47
  112. data/lib/pdk/util/filesystem.rb +138 -138
  113. data/lib/pdk/util/git.rb +179 -179
  114. data/lib/pdk/util/json_finder.rb +85 -85
  115. data/lib/pdk/util/puppet_strings.rb +125 -125
  116. data/lib/pdk/util/puppet_version.rb +266 -266
  117. data/lib/pdk/util/ruby_version.rb +179 -179
  118. data/lib/pdk/util/template_uri.rb +295 -295
  119. data/lib/pdk/util/vendored_file.rb +93 -93
  120. data/lib/pdk/util/version.rb +43 -43
  121. data/lib/pdk/util/windows/api_types.rb +82 -82
  122. data/lib/pdk/util/windows/file.rb +36 -36
  123. data/lib/pdk/util/windows/process.rb +79 -79
  124. data/lib/pdk/util/windows/string.rb +16 -16
  125. data/lib/pdk/util/windows.rb +15 -15
  126. data/lib/pdk/util.rb +278 -277
  127. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
  128. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
  129. data/lib/pdk/validate/external_command_validator.rb +208 -208
  130. data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
  131. data/lib/pdk/validate/invokable_validator.rb +228 -228
  132. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
  133. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
  134. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
  135. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
  136. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
  137. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
  138. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
  139. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
  140. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
  141. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
  142. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
  143. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
  144. data/lib/pdk/validate/validator.rb +118 -118
  145. data/lib/pdk/validate/validator_group.rb +104 -104
  146. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
  147. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
  148. data/lib/pdk/validate.rb +94 -94
  149. data/lib/pdk/version.rb +4 -4
  150. data/lib/pdk.rb +76 -76
  151. data/locales/config.yaml +21 -21
  152. data/locales/pdk.pot +2094 -2094
  153. metadata +5 -6
@@ -1,27 +1,27 @@
1
- require 'pdk'
2
- require 'tty/prompt'
3
-
4
- module PDK
5
- module CLI
6
- module Util
7
- class CommandRedirector < TTY::Prompt::AnswersCollector
8
- attr_accessor :command
9
-
10
- def pastel
11
- @pastel ||= Pastel.new
12
- end
13
-
14
- def target_command(cmd)
15
- @command = cmd
16
- end
17
-
18
- def run
19
- @prompt.puts _('Did you mean \'%{command}\'?') % { command: pastel.bold(@command) }
20
- @prompt.yes?('-->')
21
- rescue PDK::CLI::Util::Interview::READER::InputInterrupt
22
- nil
23
- end
24
- end
25
- end
26
- end
27
- end
1
+ require 'pdk'
2
+ require 'tty/prompt'
3
+
4
+ module PDK
5
+ module CLI
6
+ module Util
7
+ class CommandRedirector < TTY::Prompt::AnswersCollector
8
+ attr_accessor :command
9
+
10
+ def pastel
11
+ @pastel ||= Pastel.new
12
+ end
13
+
14
+ def target_command(cmd)
15
+ @command = cmd
16
+ end
17
+
18
+ def run
19
+ @prompt.puts _('Did you mean \'%{command}\'?') % { command: pastel.bold(@command) }
20
+ @prompt.yes?('-->')
21
+ rescue PDK::CLI::Util::Interview::READER::InputInterrupt
22
+ nil
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,72 +1,72 @@
1
- require 'tty/prompt'
2
- require 'pdk'
3
-
4
- module PDK
5
- module CLI
6
- module Util
7
- class Interview < TTY::Prompt::AnswersCollector
8
- READER = defined?(TTY::Reader) ? TTY::Reader : TTY::Prompt::Reader
9
-
10
- def pastel
11
- @pastel ||= Pastel.new
12
- end
13
-
14
- def add_questions(questions)
15
- questions.each do |question|
16
- add_question(question)
17
- end
18
- end
19
-
20
- def add_question(options = {})
21
- (@questions ||= {})[options[:name]] = options
22
- end
23
-
24
- def num_questions
25
- (@questions ||= {}).count
26
- end
27
-
28
- def run
29
- i = 1
30
- num_questions = @questions.count
31
- @questions.each do |question_name, question|
32
- @name = question_name
33
- @prompt.print pastel.bold(_('[Q %{current_number}/%{questions_total}]') % { current_number: i, questions_total: num_questions }) + ' '
34
- @prompt.puts pastel.bold(question[:question])
35
- @prompt.puts question[:help] if question.key?(:help)
36
-
37
- case question[:type]
38
- when :yes
39
- yes?(_('-->')) do |q|
40
- q.default(question[:default]) if question.key?(:default)
41
- end
42
- when :multi_select
43
- multi_select(_('-->'), per_page: question[:choices].count) do |q|
44
- q.enum ')'
45
- q.default(*question[:default]) if question.key?(:default)
46
-
47
- question[:choices].each do |text, metadata|
48
- q.choice text, metadata
49
- end
50
- end
51
- else
52
- ask(_('-->')) do |q|
53
- q.required(question.fetch(:required, false))
54
-
55
- if question.key?(:validate_pattern)
56
- q.validate(question[:validate_pattern], question[:validate_message])
57
- end
58
-
59
- q.default(question[:default]) if question.key?(:default)
60
- end
61
- end
62
- i += 1
63
- @prompt.puts ''
64
- end
65
- @answers
66
- rescue READER::InputInterrupt
67
- nil
68
- end
69
- end
70
- end
71
- end
72
- end
1
+ require 'tty/prompt'
2
+ require 'pdk'
3
+
4
+ module PDK
5
+ module CLI
6
+ module Util
7
+ class Interview < TTY::Prompt::AnswersCollector
8
+ READER = defined?(TTY::Reader) ? TTY::Reader : TTY::Prompt::Reader
9
+
10
+ def pastel
11
+ @pastel ||= Pastel.new
12
+ end
13
+
14
+ def add_questions(questions)
15
+ questions.each do |question|
16
+ add_question(question)
17
+ end
18
+ end
19
+
20
+ def add_question(options = {})
21
+ (@questions ||= {})[options[:name]] = options
22
+ end
23
+
24
+ def num_questions
25
+ (@questions ||= {}).count
26
+ end
27
+
28
+ def run
29
+ i = 1
30
+ num_questions = @questions.count
31
+ @questions.each do |question_name, question|
32
+ @name = question_name
33
+ @prompt.print pastel.bold(_('[Q %{current_number}/%{questions_total}]') % { current_number: i, questions_total: num_questions }) + ' '
34
+ @prompt.puts pastel.bold(question[:question])
35
+ @prompt.puts question[:help] if question.key?(:help)
36
+
37
+ case question[:type]
38
+ when :yes
39
+ yes?(_('-->')) do |q|
40
+ q.default(question[:default]) if question.key?(:default)
41
+ end
42
+ when :multi_select
43
+ multi_select(_('-->'), per_page: question[:choices].count) do |q|
44
+ q.enum ')'
45
+ q.default(*question[:default]) if question.key?(:default)
46
+
47
+ question[:choices].each do |text, metadata|
48
+ q.choice text, metadata
49
+ end
50
+ end
51
+ else
52
+ ask(_('-->')) do |q|
53
+ q.required(question.fetch(:required, false))
54
+
55
+ if question.key?(:validate_pattern)
56
+ q.validate(question[:validate_pattern], question[:validate_message])
57
+ end
58
+
59
+ q.default(question[:default]) if question.key?(:default)
60
+ end
61
+ end
62
+ i += 1
63
+ @prompt.puts ''
64
+ end
65
+ @answers
66
+ rescue READER::InputInterrupt
67
+ nil
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,55 +1,55 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module CLI
5
- module Util
6
- class OptionNormalizer
7
- def self.comma_separated_list_to_array(list, _options = {})
8
- raise _('Error: expected comma separated list') unless OptionValidator.comma_separated_list?(list)
9
- list.split(',').compact
10
- end
11
-
12
- # Parse one or more format:target pairs into report format
13
- # specifications.
14
- #
15
- # Each specification is a Hash with two values:
16
- # :method => The name of the method to call on the PDK::Report object
17
- # to render the report.
18
- # :target => The target to write the report to. This can be either an
19
- # IO object that implements #write, or a String filename
20
- # that will be opened for writing.
21
- #
22
- # If the target given is "stdout" or "stderr", this will convert those
23
- # strings into the appropriate IO object.
24
- #
25
- # @return [Array<Hash{Symbol=>Object}>] An array of one or more report
26
- # format specifications
27
- def self.report_formats(formats)
28
- formats.map do |f|
29
- format, target = f.split(':', 2)
30
-
31
- begin
32
- OptionValidator.enum(format, PDK::Report.formats)
33
- rescue ArgumentError
34
- raise PDK::CLI::ExitWithError, _("'%{name}' is not a valid report format (%{valid})") % {
35
- name: format,
36
- valid: PDK::Report.formats.join(', '),
37
- }
38
- end
39
-
40
- case target
41
- when 'stdout'
42
- target = $stdout
43
- when 'stderr'
44
- target = $stderr
45
- when nil
46
- target = PDK::Report.default_target
47
- end
48
-
49
- { method: "write_#{format}".to_sym, target: target }
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module CLI
5
+ module Util
6
+ class OptionNormalizer
7
+ def self.comma_separated_list_to_array(list, _options = {})
8
+ raise _('Error: expected comma separated list') unless OptionValidator.comma_separated_list?(list)
9
+ list.split(',').compact
10
+ end
11
+
12
+ # Parse one or more format:target pairs into report format
13
+ # specifications.
14
+ #
15
+ # Each specification is a Hash with two values:
16
+ # :method => The name of the method to call on the PDK::Report object
17
+ # to render the report.
18
+ # :target => The target to write the report to. This can be either an
19
+ # IO object that implements #write, or a String filename
20
+ # that will be opened for writing.
21
+ #
22
+ # If the target given is "stdout" or "stderr", this will convert those
23
+ # strings into the appropriate IO object.
24
+ #
25
+ # @return [Array<Hash{Symbol=>Object}>] An array of one or more report
26
+ # format specifications
27
+ def self.report_formats(formats)
28
+ formats.map do |f|
29
+ format, target = f.split(':', 2)
30
+
31
+ begin
32
+ OptionValidator.enum(format, PDK::Report.formats)
33
+ rescue ArgumentError
34
+ raise PDK::CLI::ExitWithError, _("'%{name}' is not a valid report format (%{valid})") % {
35
+ name: format,
36
+ valid: PDK::Report.formats.join(', '),
37
+ }
38
+ end
39
+
40
+ case target
41
+ when 'stdout'
42
+ target = $stdout
43
+ when 'stderr'
44
+ target = $stderr
45
+ when nil
46
+ target = PDK::Report.default_target
47
+ end
48
+
49
+ { method: "write_#{format}".to_sym, target: target }
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,68 +1,68 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module CLI
5
- module Util
6
- class OptionValidator
7
- def self.comma_separated_list?(list, _options = {})
8
- (list =~ %r{^[\w\-]+(?:,[\w\-]+)+$}) ? true : false
9
- end
10
-
11
- # @return [Boolean] true if the fact name is valid
12
- def self.valid_fact_name?(name)
13
- name.length > 1
14
- end
15
-
16
- def self.enum(val, valid_entries, _options = {})
17
- vals = val.is_a?(Array) ? val : [val]
18
- invalid_entries = vals.reject { |e| valid_entries.include?(e) }
19
-
20
- unless invalid_entries.empty?
21
- raise ArgumentError, _('Error: the following values are invalid: %{invalid_entries}') % { invalid_entries: invalid_entries }
22
- end
23
-
24
- val
25
- end
26
-
27
- # Validate the module name against the regular expression in the
28
- # documentation: https://docs.puppet.com/puppet/4.10/modules_fundamentals.html#allowed-module-names
29
- def self.valid_module_name?(string)
30
- !(string =~ %r{\A[a-z][a-z0-9_]*\Z}).nil?
31
- end
32
- singleton_class.send(:alias_method, :valid_task_name?, :valid_module_name?)
33
-
34
- # https://puppet.com/docs/puppet/5.3/custom_types.html#creating-a-type only says the name has to be a ruby symbol.
35
- # Let's assume that only strings similar to module names can actually be resolved by the puppet language.
36
- singleton_class.send(:alias_method, :valid_provider_name?, :valid_module_name?)
37
-
38
- # The name has to be a ruby symbol.
39
- # While overly strict, let's apply the provider and module name rules for consistency.
40
- singleton_class.send(:alias_method, :valid_transport_name?, :valid_provider_name?)
41
-
42
- # Validate a Puppet namespace against the regular expression in the
43
- # documentation: https://docs.puppet.com/puppet/4.10/lang_reserved.html#classes-and-defined-resource-types
44
- def self.valid_namespace?(string)
45
- return false if (string || '').split('::').last == 'init'
46
-
47
- !(string =~ %r{\A([a-z][a-z0-9_]*)(::[a-z][a-z0-9_]*)*\Z}).nil?
48
- end
49
- singleton_class.send(:alias_method, :valid_function_name?, :valid_namespace?)
50
-
51
- singleton_class.send(:alias_method, :valid_class_name?, :valid_namespace?)
52
- singleton_class.send(:alias_method, :valid_defined_type_name?, :valid_namespace?)
53
-
54
- # Validate that a class/defined type parameter matches the regular
55
- # expression in the documentation: https://docs.puppet.com/puppet/4.10/lang_reserved.html#parameters
56
- # The parameter should also not be a reserved word or overload
57
- # a metaparameter.
58
- def self.valid_param_name?(string)
59
- reserved_words = %w[trusted facts server_facts title name].freeze
60
- metaparams = %w[alias audit before loglevel noop notify require schedule stage subscribe tag].freeze
61
- return false if reserved_words.include?(string) || metaparams.include?(string)
62
-
63
- !(string =~ %r{\A[a-z][a-zA-Z0-9_]*\Z}).nil?
64
- end
65
- end
66
- end
67
- end
68
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module CLI
5
+ module Util
6
+ class OptionValidator
7
+ def self.comma_separated_list?(list, _options = {})
8
+ (list =~ %r{^[\w\-]+(?:,[\w\-]+)+$}) ? true : false
9
+ end
10
+
11
+ # @return [Boolean] true if the fact name is valid
12
+ def self.valid_fact_name?(name)
13
+ name.length > 1
14
+ end
15
+
16
+ def self.enum(val, valid_entries, _options = {})
17
+ vals = val.is_a?(Array) ? val : [val]
18
+ invalid_entries = vals.reject { |e| valid_entries.include?(e) }
19
+
20
+ unless invalid_entries.empty?
21
+ raise ArgumentError, _('Error: the following values are invalid: %{invalid_entries}') % { invalid_entries: invalid_entries }
22
+ end
23
+
24
+ val
25
+ end
26
+
27
+ # Validate the module name against the regular expression in the
28
+ # documentation: https://docs.puppet.com/puppet/4.10/modules_fundamentals.html#allowed-module-names
29
+ def self.valid_module_name?(string)
30
+ !(string =~ %r{\A[a-z][a-z0-9_]*\Z}).nil?
31
+ end
32
+ singleton_class.send(:alias_method, :valid_task_name?, :valid_module_name?)
33
+
34
+ # https://puppet.com/docs/puppet/5.3/custom_types.html#creating-a-type only says the name has to be a ruby symbol.
35
+ # Let's assume that only strings similar to module names can actually be resolved by the puppet language.
36
+ singleton_class.send(:alias_method, :valid_provider_name?, :valid_module_name?)
37
+
38
+ # The name has to be a ruby symbol.
39
+ # While overly strict, let's apply the provider and module name rules for consistency.
40
+ singleton_class.send(:alias_method, :valid_transport_name?, :valid_provider_name?)
41
+
42
+ # Validate a Puppet namespace against the regular expression in the
43
+ # documentation: https://docs.puppet.com/puppet/4.10/lang_reserved.html#classes-and-defined-resource-types
44
+ def self.valid_namespace?(string)
45
+ return false if (string || '').split('::').last == 'init'
46
+
47
+ !(string =~ %r{\A([a-z][a-z0-9_]*)(::[a-z][a-z0-9_]*)*\Z}).nil?
48
+ end
49
+ singleton_class.send(:alias_method, :valid_function_name?, :valid_namespace?)
50
+
51
+ singleton_class.send(:alias_method, :valid_class_name?, :valid_namespace?)
52
+ singleton_class.send(:alias_method, :valid_defined_type_name?, :valid_namespace?)
53
+
54
+ # Validate that a class/defined type parameter matches the regular
55
+ # expression in the documentation: https://docs.puppet.com/puppet/4.10/lang_reserved.html#parameters
56
+ # The parameter should also not be a reserved word or overload
57
+ # a metaparameter.
58
+ def self.valid_param_name?(string)
59
+ reserved_words = %w[trusted facts server_facts title name].freeze
60
+ metaparams = %w[alias audit before loglevel noop notify require schedule stage subscribe tag].freeze
61
+ return false if reserved_words.include?(string) || metaparams.include?(string)
62
+
63
+ !(string =~ %r{\A[a-z][a-zA-Z0-9_]*\Z}).nil?
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,13 +1,13 @@
1
- require 'tty-spinner'
2
-
3
- # Replace the built-in tty check in tty-spinner with our own implementation
4
- # that allows us to mock the behaviour during acceptance tests.
5
- module TTY
6
- class Spinner
7
- def tty?
8
- require 'pdk/cli/util'
9
-
10
- PDK::CLI::Util.interactive?
11
- end
12
- end
13
- end
1
+ require 'tty-spinner'
2
+
3
+ # Replace the built-in tty check in tty-spinner with our own implementation
4
+ # that allows us to mock the behaviour during acceptance tests.
5
+ module TTY
6
+ class Spinner
7
+ def tty?
8
+ require 'pdk/cli/util'
9
+
10
+ PDK::CLI::Util.interactive?
11
+ end
12
+ end
13
+ end
@@ -1,82 +1,82 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module CLI
5
- module Util
6
- module UpdateManagerPrinter
7
- # Prints the summary for a PDK::Module::UpdateManager Object
8
- # @param update_manager [PDK::Module::UpdateManager] The object to print a summary of
9
- # @param options [Hash{Object => Object}] A list of options when printing
10
- # @option options [Boolean] :tense Whether to use future (:future) or past (:past) tense when printing the summary ("Files to be added" versus "Files added"). Default is :future
11
- #
12
- # @return [void]
13
- def self.print_summary(update_manager, options = {})
14
- require 'pdk/report'
15
-
16
- options = {
17
- tense: :future,
18
- }.merge(options)
19
-
20
- footer = false
21
-
22
- summary(update_manager).each do |category, files|
23
- next if files.empty?
24
-
25
- PDK::Report.default_target.puts('')
26
- PDK::Report.default_target.puts(generate_banner("Files #{(options[:tense] == :future) ? 'to be ' : ''}#{category}", 40))
27
- PDK::Report.default_target.puts(files.map(&:to_s).join("\n"))
28
- footer = true
29
- end
30
-
31
- if footer # rubocop:disable Style/GuardClause No.
32
- PDK::Report.default_target.puts('')
33
- PDK::Report.default_target.puts(generate_banner('', 40))
34
- end
35
- end
36
-
37
- #:nocov: Tested as part of the public methods
38
- # Returns a hash, summarizing the contents of the Update Manager object
39
- # @param update_manager [PDK::Module::UpdateManager] The object to create a summary of
40
- #
41
- # @return [Hash{Symbol => Array[String]}] A hash of each category and the file paths in each category
42
- def self.summary(update_manager)
43
- summary = {}
44
- update_manager.changes.each do |category, update_category|
45
- if update_category.respond_to?(:keys)
46
- updated_files = update_category.keys
47
- else
48
- begin
49
- updated_files = update_category.map { |file| file[:path] }
50
- rescue TypeError
51
- updated_files = update_category.to_a
52
- end
53
- end
54
-
55
- summary[category] = updated_files
56
- end
57
-
58
- summary
59
- end
60
- private_class_method :summary
61
-
62
- # Creates a line of text, with `text` centered in the middle
63
- # @param text [String] The text to put in the middle of the banner
64
- # @param width [Integer] The width of the banner in characters. Default is 80
65
- # @return [String] The generated banner
66
- def self.generate_banner(text, width = 80)
67
- padding = width - text.length
68
- banner = ''
69
- padding_char = '-'
70
-
71
- (padding / 2.0).ceil.times { banner << padding_char }
72
- banner << text
73
- (padding / 2.0).floor.times { banner << padding_char }
74
-
75
- banner
76
- end
77
- private_class_method :generate_banner
78
- #:nocov:
79
- end
80
- end
81
- end
82
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module CLI
5
+ module Util
6
+ module UpdateManagerPrinter
7
+ # Prints the summary for a PDK::Module::UpdateManager Object
8
+ # @param update_manager [PDK::Module::UpdateManager] The object to print a summary of
9
+ # @param options [Hash{Object => Object}] A list of options when printing
10
+ # @option options [Boolean] :tense Whether to use future (:future) or past (:past) tense when printing the summary ("Files to be added" versus "Files added"). Default is :future
11
+ #
12
+ # @return [void]
13
+ def self.print_summary(update_manager, options = {})
14
+ require 'pdk/report'
15
+
16
+ options = {
17
+ tense: :future,
18
+ }.merge(options)
19
+
20
+ footer = false
21
+
22
+ summary(update_manager).each do |category, files|
23
+ next if files.empty?
24
+
25
+ PDK::Report.default_target.puts('')
26
+ PDK::Report.default_target.puts(generate_banner("Files #{(options[:tense] == :future) ? 'to be ' : ''}#{category}", 40))
27
+ PDK::Report.default_target.puts(files.map(&:to_s).join("\n"))
28
+ footer = true
29
+ end
30
+
31
+ if footer # rubocop:disable Style/GuardClause No.
32
+ PDK::Report.default_target.puts('')
33
+ PDK::Report.default_target.puts(generate_banner('', 40))
34
+ end
35
+ end
36
+
37
+ #:nocov: Tested as part of the public methods
38
+ # Returns a hash, summarizing the contents of the Update Manager object
39
+ # @param update_manager [PDK::Module::UpdateManager] The object to create a summary of
40
+ #
41
+ # @return [Hash{Symbol => Array[String]}] A hash of each category and the file paths in each category
42
+ def self.summary(update_manager)
43
+ summary = {}
44
+ update_manager.changes.each do |category, update_category|
45
+ if update_category.respond_to?(:keys)
46
+ updated_files = update_category.keys
47
+ else
48
+ begin
49
+ updated_files = update_category.map { |file| file[:path] }
50
+ rescue TypeError
51
+ updated_files = update_category.to_a
52
+ end
53
+ end
54
+
55
+ summary[category] = updated_files
56
+ end
57
+
58
+ summary
59
+ end
60
+ private_class_method :summary
61
+
62
+ # Creates a line of text, with `text` centered in the middle
63
+ # @param text [String] The text to put in the middle of the banner
64
+ # @param width [Integer] The width of the banner in characters. Default is 80
65
+ # @return [String] The generated banner
66
+ def self.generate_banner(text, width = 80)
67
+ padding = width - text.length
68
+ banner = ''
69
+ padding_char = '-'
70
+
71
+ (padding / 2.0).ceil.times { banner << padding_char }
72
+ banner << text
73
+ (padding / 2.0).floor.times { banner << padding_char }
74
+
75
+ banner
76
+ end
77
+ private_class_method :generate_banner
78
+ #:nocov:
79
+ end
80
+ end
81
+ end
82
+ end