pdk 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,119 +1,119 @@
1
- module PDK::CLI
2
- module Set
3
- module Config
4
- ALLOWED_TYPE_NAMES = %w[array boolean number string].freeze
5
-
6
- # :nocov:
7
- def self.pretty_allowed_names
8
- ALLOWED_TYPE_NAMES.map { |name| "'#{name}'" }.join(', ')
9
- end
10
- # :nocov:
11
-
12
- def self.transform_value(type_name, value)
13
- normalized_name = type_name.downcase.strip
14
- unless ALLOWED_TYPE_NAMES.include?(normalized_name)
15
- raise PDK::CLI::ExitWithError, _('Unknown type %{type_name}. Expected one of %{allowed}') % { type_name: type_name, allowed: pretty_allowed_names }
16
- end
17
-
18
- # Short circuit string conversions as it's trivial
19
- if normalized_name == 'string'
20
- raise PDK::CLI::ExitWithError, _('An error occured converting \'%{value}\' into a %{type_name}') % { value: value.nil? ? 'nil' : value, type_name: type_name } unless value.is_a?(String)
21
- return value
22
- end
23
-
24
- begin
25
- case normalized_name
26
- when 'array'
27
- convert_to_array(value)
28
- when 'boolean'
29
- convert_to_boolean(value)
30
- when 'number'
31
- convert_to_number(value)
32
- else
33
- value
34
- end
35
- rescue ArgumentError, TypeError
36
- raise PDK::CLI::ExitWithError, _('An error occured converting \'%{value}\' into a %{type_name}') % { value: value.nil? ? 'nil' : value, type_name: type_name }
37
- end
38
- end
39
-
40
- def self.convert_to_array(value)
41
- return [] if value.nil?
42
- value.is_a?(Array) ? value : [value]
43
- end
44
- private_class_method :convert_to_array
45
-
46
- def self.convert_to_boolean(value)
47
- string_val = value.to_s.strip.downcase
48
-
49
- return true if %w[yes true -1 1].include?(string_val)
50
- return false if %w[no false 0].include?(string_val)
51
-
52
- raise ArgumentError
53
- end
54
- private_class_method :convert_to_boolean
55
-
56
- def self.convert_to_number(value)
57
- float_val = Float(value)
58
- # Return an Integer if this is actually and Integer, otherwise return the float
59
- (float_val.truncate == float_val) ? float_val.truncate : float_val
60
- end
61
- private_class_method :convert_to_number
62
-
63
- def self.run(opts, args)
64
- item_name = (args.count > 0) ? args[0] : nil
65
- item_value = (args.count > 1) ? args[1] : nil
66
-
67
- opts[:type] = opts[:as] if opts[:type].nil? && !opts[:as].nil?
68
- force = opts[:force] || false
69
-
70
- # Transform the value if we need to
71
- item_value = PDK::CLI::Set::Config.transform_value(opts[:type], item_value) unless opts[:type].nil?
72
-
73
- raise PDK::CLI::ExitWithError, _('Configuration name is required') if item_name.nil?
74
- raise PDK::CLI::ExitWithError, _('Configuration value is required. If you wish to remove a value use \'pdk remove config\'') if item_value.nil?
75
-
76
- current_value = PDK.config.get(item_name)
77
- raise PDK::CLI::ExitWithError, _("The configuration item '%{name}' can not have a value set.") % { name: item_name } if current_value.is_a?(PDK::Config::Namespace)
78
-
79
- # If we're forcing the value, don't do any munging
80
- unless force
81
- # Check if the setting already exists
82
- if current_value.is_a?(Array) && current_value.include?(item_value)
83
- PDK.logger.info(_("No changes made to '%{name}' as it already contains value '%{to}'") % { name: item_name, to: item_value })
84
- return 0
85
- end
86
- end
87
-
88
- new_value = PDK.config.set(item_name, item_value, force: opts[:force])
89
- if current_value.nil? || force
90
- PDK.logger.info(_("Set initial value of '%{name}' to '%{to}'") % { name: item_name, to: new_value })
91
- elsif current_value.is_a?(Array)
92
- # Arrays have a special output format
93
- PDK.logger.info(_("Added new value '%{to}' to '%{name}'") % { name: item_name, to: item_value })
94
- else
95
- PDK.logger.info(_("Changed existing value of '%{name}' from '%{from}' to '%{to}'") % { name: item_name, from: current_value, to: new_value })
96
- end
97
-
98
- # Same output as `get config`
99
- $stdout.puts _('%{name}=%{value}') % { name: item_name, value: PDK.config.get(item_name) }
100
- 0
101
- end
102
- end
103
- end
104
-
105
- @set_config_cmd = @set_cmd.define_command do
106
- name 'config'
107
- usage _('config [name] [value]')
108
- summary _('Set or update the configuration for <name>')
109
-
110
- option :f, :force, _('Force the configuration setting to be overwitten.'), argument: :forbidden
111
-
112
- option :t, :type, _('The type of value to set. Acceptable values: %{values}') % { values: PDK::CLI::Set::Config.pretty_allowed_names }, argument: :required
113
- option nil, :as, _('Alias of --type'), argument: :required
114
-
115
- run do |opts, args, _cmd|
116
- exit PDK::CLI::Set::Config.run(opts, args)
117
- end
118
- end
119
- end
1
+ module PDK::CLI
2
+ module Set
3
+ module Config
4
+ ALLOWED_TYPE_NAMES = %w[array boolean number string].freeze
5
+
6
+ # :nocov:
7
+ def self.pretty_allowed_names
8
+ ALLOWED_TYPE_NAMES.map { |name| "'#{name}'" }.join(', ')
9
+ end
10
+ # :nocov:
11
+
12
+ def self.transform_value(type_name, value)
13
+ normalized_name = type_name.downcase.strip
14
+ unless ALLOWED_TYPE_NAMES.include?(normalized_name)
15
+ raise PDK::CLI::ExitWithError, _('Unknown type %{type_name}. Expected one of %{allowed}') % { type_name: type_name, allowed: pretty_allowed_names }
16
+ end
17
+
18
+ # Short circuit string conversions as it's trivial
19
+ if normalized_name == 'string'
20
+ raise PDK::CLI::ExitWithError, _('An error occured converting \'%{value}\' into a %{type_name}') % { value: value.nil? ? 'nil' : value, type_name: type_name } unless value.is_a?(String)
21
+ return value
22
+ end
23
+
24
+ begin
25
+ case normalized_name
26
+ when 'array'
27
+ convert_to_array(value)
28
+ when 'boolean'
29
+ convert_to_boolean(value)
30
+ when 'number'
31
+ convert_to_number(value)
32
+ else
33
+ value
34
+ end
35
+ rescue ArgumentError, TypeError
36
+ raise PDK::CLI::ExitWithError, _('An error occured converting \'%{value}\' into a %{type_name}') % { value: value.nil? ? 'nil' : value, type_name: type_name }
37
+ end
38
+ end
39
+
40
+ def self.convert_to_array(value)
41
+ return [] if value.nil?
42
+ value.is_a?(Array) ? value : [value]
43
+ end
44
+ private_class_method :convert_to_array
45
+
46
+ def self.convert_to_boolean(value)
47
+ string_val = value.to_s.strip.downcase
48
+
49
+ return true if %w[yes true -1 1].include?(string_val)
50
+ return false if %w[no false 0].include?(string_val)
51
+
52
+ raise ArgumentError
53
+ end
54
+ private_class_method :convert_to_boolean
55
+
56
+ def self.convert_to_number(value)
57
+ float_val = Float(value)
58
+ # Return an Integer if this is actually and Integer, otherwise return the float
59
+ (float_val.truncate == float_val) ? float_val.truncate : float_val
60
+ end
61
+ private_class_method :convert_to_number
62
+
63
+ def self.run(opts, args)
64
+ item_name = (args.count > 0) ? args[0] : nil
65
+ item_value = (args.count > 1) ? args[1] : nil
66
+
67
+ opts[:type] = opts[:as] if opts[:type].nil? && !opts[:as].nil?
68
+ force = opts[:force] || false
69
+
70
+ # Transform the value if we need to
71
+ item_value = PDK::CLI::Set::Config.transform_value(opts[:type], item_value) unless opts[:type].nil?
72
+
73
+ raise PDK::CLI::ExitWithError, _('Configuration name is required') if item_name.nil?
74
+ raise PDK::CLI::ExitWithError, _('Configuration value is required. If you wish to remove a value use \'pdk remove config\'') if item_value.nil?
75
+
76
+ current_value = PDK.config.get(item_name)
77
+ raise PDK::CLI::ExitWithError, _("The configuration item '%{name}' can not have a value set.") % { name: item_name } if current_value.is_a?(PDK::Config::Namespace)
78
+
79
+ # If we're forcing the value, don't do any munging
80
+ unless force
81
+ # Check if the setting already exists
82
+ if current_value.is_a?(Array) && current_value.include?(item_value)
83
+ PDK.logger.info(_("No changes made to '%{name}' as it already contains value '%{to}'") % { name: item_name, to: item_value })
84
+ return 0
85
+ end
86
+ end
87
+
88
+ new_value = PDK.config.set(item_name, item_value, force: opts[:force])
89
+ if current_value.nil? || force
90
+ PDK.logger.info(_("Set initial value of '%{name}' to '%{to}'") % { name: item_name, to: new_value })
91
+ elsif current_value.is_a?(Array)
92
+ # Arrays have a special output format
93
+ PDK.logger.info(_("Added new value '%{to}' to '%{name}'") % { name: item_name, to: item_value })
94
+ else
95
+ PDK.logger.info(_("Changed existing value of '%{name}' from '%{from}' to '%{to}'") % { name: item_name, from: current_value, to: new_value })
96
+ end
97
+
98
+ # Same output as `get config`
99
+ $stdout.puts _('%{name}=%{value}') % { name: item_name, value: PDK.config.get(item_name) }
100
+ 0
101
+ end
102
+ end
103
+ end
104
+
105
+ @set_config_cmd = @set_cmd.define_command do
106
+ name 'config'
107
+ usage _('config [name] [value]')
108
+ summary _('Set or update the configuration for <name>')
109
+
110
+ option :f, :force, _('Force the configuration setting to be overwitten.'), argument: :forbidden
111
+
112
+ option :t, :type, _('The type of value to set. Acceptable values: %{values}') % { values: PDK::CLI::Set::Config.pretty_allowed_names }, argument: :required
113
+ option nil, :as, _('Alias of --type'), argument: :required
114
+
115
+ run do |opts, args, _cmd|
116
+ exit PDK::CLI::Set::Config.run(opts, args)
117
+ end
118
+ end
119
+ end
data/lib/pdk/cli/set.rb CHANGED
@@ -1,20 +1,20 @@
1
- module PDK::CLI
2
- @set_cmd = @base_cmd.define_command do
3
- name 'set'
4
- usage _('set [subcommand] [options]')
5
- summary _('Set or update information about the PDK or current project.')
6
- default_subcommand 'help'
7
-
8
- run do |_opts, args, _cmd|
9
- if args == ['help']
10
- PDK::CLI.run(%w[set --help])
11
- exit 0
12
- end
13
-
14
- PDK::CLI.run(%w[set help]) if args.empty?
15
- end
16
- end
17
- @set_cmd.add_command Cri::Command.new_basic_help
18
- end
19
-
20
- require 'pdk/cli/set/config'
1
+ module PDK::CLI
2
+ @set_cmd = @base_cmd.define_command do
3
+ name 'set'
4
+ usage _('set [subcommand] [options]')
5
+ summary _('Set or update information about the PDK or current project.')
6
+ default_subcommand 'help'
7
+
8
+ run do |_opts, args, _cmd|
9
+ if args == ['help']
10
+ PDK::CLI.run(%w[set --help])
11
+ exit 0
12
+ end
13
+
14
+ PDK::CLI.run(%w[set help]) if args.empty?
15
+ end
16
+ end
17
+ @set_cmd.add_command Cri::Command.new_basic_help
18
+ end
19
+
20
+ require 'pdk/cli/set/config'
@@ -1,90 +1,90 @@
1
- module PDK::CLI
2
- @test_unit_cmd = @test_cmd.define_command do
3
- name 'unit'
4
- usage _('unit [options]')
5
- summary _('Run unit tests.')
6
-
7
- PDK::CLI.puppet_version_options(self)
8
- PDK::CLI.puppet_dev_option(self)
9
- flag nil, :list, _('List all available unit test files.')
10
- flag nil, :parallel, _('Run unit tests in parallel.')
11
- flag :v, :verbose, _('More verbose --list output. Displays a list of examples in each unit test file.')
12
- flag :c, 'clean-fixtures', _('Clean up downloaded fixtures after the test run.')
13
-
14
- option nil, :tests, _('Specify a comma-separated list of unit test files to run.'), argument: :required, default: '' do |values|
15
- require 'pdk/cli/util/option_validator'
16
- PDK::CLI::Util::OptionValidator.comma_separated_list?(values)
17
- end
18
-
19
- # TODO
20
- # option nil, :runner_options, _("options to pass through to the actual test-runner"), argument: :required
21
-
22
- run do |opts, _args, _cmd|
23
- require 'pdk/tests/unit'
24
- require 'pdk/report'
25
- require 'pdk/util/bundler'
26
-
27
- PDK::CLI::Util.validate_puppet_version_opts(opts)
28
-
29
- PDK::CLI::Util.ensure_in_module!(
30
- message: _('Unit tests can only be run from inside a valid module directory.'),
31
- log_level: :info,
32
- )
33
-
34
- PDK::CLI::Util.module_version_check
35
-
36
- PDK::CLI::Util.analytics_screen_view('test_unit', opts)
37
-
38
- # Ensure that the bundled gems are up to date and correct Ruby is activated before running or listing tests.
39
- puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
40
- PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
41
-
42
- opts.merge!(puppet_env[:gemset])
43
-
44
- PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
45
-
46
- report = nil
47
-
48
- if opts[:list]
49
- examples = PDK::Test::Unit.list(opts)
50
-
51
- if examples.empty?
52
- puts _('No unit test files with examples were found.')
53
- else
54
- puts _('Unit Test Files:')
55
- files = examples.map { |example| example[:file_path] }
56
- files.uniq.each do |file|
57
- puts _(file)
58
-
59
- next unless opts[:verbose]
60
-
61
- file_examples = examples.select { |example| example[:file_path] == file }
62
- file_examples.each do |file_example|
63
- puts _("\t%{id}\t%{description}" % { id: file_example[:id], description: file_example[:full_description] })
64
- end
65
- end
66
- end
67
- else
68
- report = PDK::Report.new
69
- report_formats = if opts[:format]
70
- opts[:interactive] = false
71
- PDK::CLI::Util::OptionNormalizer.report_formats(opts[:format])
72
- else
73
- opts[:interactive] = true
74
- [{
75
- method: PDK::Report.default_format,
76
- target: PDK::Report.default_target,
77
- }]
78
- end
79
-
80
- exit_code = PDK::Test::Unit.invoke(report, opts)
81
-
82
- report_formats.each do |format|
83
- report.send(format[:method], format[:target])
84
- end
85
-
86
- exit exit_code
87
- end
88
- end
89
- end
90
- end
1
+ module PDK::CLI
2
+ @test_unit_cmd = @test_cmd.define_command do
3
+ name 'unit'
4
+ usage _('unit [options]')
5
+ summary _('Run unit tests.')
6
+
7
+ PDK::CLI.puppet_version_options(self)
8
+ PDK::CLI.puppet_dev_option(self)
9
+ flag nil, :list, _('List all available unit test files.')
10
+ flag nil, :parallel, _('Run unit tests in parallel.')
11
+ flag :v, :verbose, _('More verbose --list output. Displays a list of examples in each unit test file.')
12
+ flag :c, 'clean-fixtures', _('Clean up downloaded fixtures after the test run.')
13
+
14
+ option nil, :tests, _('Specify a comma-separated list of unit test files to run.'), argument: :required, default: '' do |values|
15
+ require 'pdk/cli/util/option_validator'
16
+ PDK::CLI::Util::OptionValidator.comma_separated_list?(values)
17
+ end
18
+
19
+ # TODO
20
+ # option nil, :runner_options, _("options to pass through to the actual test-runner"), argument: :required
21
+
22
+ run do |opts, _args, _cmd|
23
+ require 'pdk/tests/unit'
24
+ require 'pdk/report'
25
+ require 'pdk/util/bundler'
26
+
27
+ PDK::CLI::Util.validate_puppet_version_opts(opts)
28
+
29
+ PDK::CLI::Util.ensure_in_module!(
30
+ message: _('Unit tests can only be run from inside a valid module directory.'),
31
+ log_level: :info,
32
+ )
33
+
34
+ PDK::CLI::Util.module_version_check
35
+
36
+ PDK::CLI::Util.analytics_screen_view('test_unit', opts)
37
+
38
+ # Ensure that the bundled gems are up to date and correct Ruby is activated before running or listing tests.
39
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
40
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
41
+
42
+ opts.merge!(puppet_env[:gemset])
43
+
44
+ PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
45
+
46
+ report = nil
47
+
48
+ if opts[:list]
49
+ examples = PDK::Test::Unit.list(opts)
50
+
51
+ if examples.empty?
52
+ puts _('No unit test files with examples were found.')
53
+ else
54
+ puts _('Unit Test Files:')
55
+ files = examples.map { |example| example[:file_path] }
56
+ files.uniq.each do |file|
57
+ puts _(file)
58
+
59
+ next unless opts[:verbose]
60
+
61
+ file_examples = examples.select { |example| example[:file_path] == file }
62
+ file_examples.each do |file_example|
63
+ puts _("\t%{id}\t%{description}" % { id: file_example[:id], description: file_example[:full_description] })
64
+ end
65
+ end
66
+ end
67
+ else
68
+ report = PDK::Report.new
69
+ report_formats = if opts[:format]
70
+ opts[:interactive] = false
71
+ PDK::CLI::Util::OptionNormalizer.report_formats(opts[:format])
72
+ else
73
+ opts[:interactive] = true
74
+ [{
75
+ method: PDK::Report.default_format,
76
+ target: PDK::Report.default_target,
77
+ }]
78
+ end
79
+
80
+ exit_code = PDK::Test::Unit.invoke(report, opts)
81
+
82
+ report_formats.each do |format|
83
+ report.send(format[:method], format[:target])
84
+ end
85
+
86
+ exit exit_code
87
+ end
88
+ end
89
+ end
90
+ end
data/lib/pdk/cli/test.rb CHANGED
@@ -1,11 +1,11 @@
1
- module PDK::CLI
2
- @test_cmd = @base_cmd.define_command do
3
- name 'test'
4
- usage _('test [subcommand] [options]')
5
- summary _('Run tests.')
6
- default_subcommand 'help'
7
- end
8
- @test_cmd.add_command Cri::Command.new_basic_help
9
- end
10
-
11
- require 'pdk/cli/test/unit'
1
+ module PDK::CLI
2
+ @test_cmd = @base_cmd.define_command do
3
+ name 'test'
4
+ usage _('test [subcommand] [options]')
5
+ summary _('Run tests.')
6
+ default_subcommand 'help'
7
+ end
8
+ @test_cmd.add_command Cri::Command.new_basic_help
9
+ end
10
+
11
+ require 'pdk/cli/test/unit'
@@ -1,64 +1,64 @@
1
- module PDK::CLI
2
- @update_cmd = @base_cmd.define_command do
3
- name 'update'
4
- usage _('update [options]')
5
- summary _('Update a module that has been created by or converted for use by PDK.')
6
-
7
- flag nil, :noop, _('Do not update the module, just output what would be done.')
8
- flag nil, :force, _('Update the module automatically, with no prompts.')
9
-
10
- PDK::CLI.template_ref_option(self)
11
-
12
- run do |opts, _args, _cmd|
13
- # Write the context information to the debug log
14
- PDK.context.to_debug_log
15
-
16
- unless PDK.context.is_a?(PDK::Context::Module)
17
- raise PDK::CLI::ExitWithError, _('`pdk update` can only be run from inside a valid module directory.')
18
- end
19
-
20
- raise PDK::CLI::ExitWithError, _('This module does not appear to be PDK compatible. To make the module compatible with PDK, run `pdk convert`.') unless PDK::Util.module_pdk_compatible?
21
-
22
- if opts[:noop] && opts[:force]
23
- raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when updating a module')
24
- end
25
-
26
- if Gem::Version.new(PDK::VERSION) < Gem::Version.new(PDK::Util.module_pdk_version)
27
- PDK.logger.warn _(
28
- 'This module has been updated to PDK %{module_pdk_version} which ' \
29
- 'is newer than your PDK version (%{user_pdk_version}), proceed ' \
30
- 'with caution!',
31
- ) % {
32
- module_pdk_version: PDK::Util.module_pdk_version,
33
- user_pdk_version: PDK::VERSION,
34
- }
35
-
36
- unless opts[:force]
37
- raise PDK::CLI::ExitWithError, _(
38
- 'Please update your PDK installation and try again. ' \
39
- 'You may also use the --force flag to override this and ' \
40
- 'continue at your own risk.',
41
- )
42
- end
43
- end
44
-
45
- PDK::CLI::Util.analytics_screen_view('update', opts)
46
-
47
- updater = PDK::Module::Update.new(PDK.context.root_path, opts)
48
-
49
- if updater.pinned_to_puppetlabs_template_tag?
50
- PDK.logger.info _(
51
- 'This module is currently pinned to version %{current_version} ' \
52
- 'of the default template. If you would like to update your ' \
53
- 'module to the latest version of the template, please run `pdk ' \
54
- 'update --template-ref %{new_version}`.',
55
- ) % {
56
- current_version: updater.template_uri.uri_fragment,
57
- new_version: PDK::TEMPLATE_REF,
58
- }
59
- end
60
-
61
- updater.run
62
- end
63
- end
64
- end
1
+ module PDK::CLI
2
+ @update_cmd = @base_cmd.define_command do
3
+ name 'update'
4
+ usage _('update [options]')
5
+ summary _('Update a module that has been created by or converted for use by PDK.')
6
+
7
+ flag nil, :noop, _('Do not update the module, just output what would be done.')
8
+ flag nil, :force, _('Update the module automatically, with no prompts.')
9
+
10
+ PDK::CLI.template_ref_option(self)
11
+
12
+ run do |opts, _args, _cmd|
13
+ # Write the context information to the debug log
14
+ PDK.context.to_debug_log
15
+
16
+ unless PDK.context.is_a?(PDK::Context::Module)
17
+ raise PDK::CLI::ExitWithError, _('`pdk update` can only be run from inside a valid module directory.')
18
+ end
19
+
20
+ raise PDK::CLI::ExitWithError, _('This module does not appear to be PDK compatible. To make the module compatible with PDK, run `pdk convert`.') unless PDK::Util.module_pdk_compatible?
21
+
22
+ if opts[:noop] && opts[:force]
23
+ raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when updating a module')
24
+ end
25
+
26
+ if Gem::Version.new(PDK::VERSION) < Gem::Version.new(PDK::Util.module_pdk_version)
27
+ PDK.logger.warn _(
28
+ 'This module has been updated to PDK %{module_pdk_version} which ' \
29
+ 'is newer than your PDK version (%{user_pdk_version}), proceed ' \
30
+ 'with caution!',
31
+ ) % {
32
+ module_pdk_version: PDK::Util.module_pdk_version,
33
+ user_pdk_version: PDK::VERSION,
34
+ }
35
+
36
+ unless opts[:force]
37
+ raise PDK::CLI::ExitWithError, _(
38
+ 'Please update your PDK installation and try again. ' \
39
+ 'You may also use the --force flag to override this and ' \
40
+ 'continue at your own risk.',
41
+ )
42
+ end
43
+ end
44
+
45
+ PDK::CLI::Util.analytics_screen_view('update', opts)
46
+
47
+ updater = PDK::Module::Update.new(PDK.context.root_path, opts)
48
+
49
+ if updater.pinned_to_puppetlabs_template_tag?
50
+ PDK.logger.info _(
51
+ 'This module is currently pinned to version %{current_version} ' \
52
+ 'of the default template. If you would like to update your ' \
53
+ 'module to the latest version of the template, please run `pdk ' \
54
+ 'update --template-ref %{new_version}`.',
55
+ ) % {
56
+ current_version: updater.template_uri.uri_fragment,
57
+ new_version: PDK::TEMPLATE_REF,
58
+ }
59
+ end
60
+
61
+ updater.run
62
+ end
63
+ end
64
+ end