pdk 2.7.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +2 -48
  4. data/lib/pdk/analytics/client/google_analytics.rb +22 -26
  5. data/lib/pdk/analytics/util.rb +0 -1
  6. data/lib/pdk/analytics.rb +1 -1
  7. data/lib/pdk/bolt.rb +1 -0
  8. data/lib/pdk/cli/build.rb +53 -56
  9. data/lib/pdk/cli/bundle.rb +34 -33
  10. data/lib/pdk/cli/console.rb +136 -134
  11. data/lib/pdk/cli/convert.rb +39 -41
  12. data/lib/pdk/cli/env.rb +49 -47
  13. data/lib/pdk/cli/errors.rb +1 -2
  14. data/lib/pdk/cli/exec/command.rb +23 -29
  15. data/lib/pdk/cli/exec/interactive_command.rb +7 -12
  16. data/lib/pdk/cli/exec.rb +4 -11
  17. data/lib/pdk/cli/exec_group.rb +3 -2
  18. data/lib/pdk/cli/get/config.rb +21 -19
  19. data/lib/pdk/cli/get.rb +15 -13
  20. data/lib/pdk/cli/new/class.rb +22 -22
  21. data/lib/pdk/cli/new/defined_type.rb +22 -22
  22. data/lib/pdk/cli/new/fact.rb +19 -19
  23. data/lib/pdk/cli/new/function.rb +20 -20
  24. data/lib/pdk/cli/new/module.rb +40 -38
  25. data/lib/pdk/cli/new/provider.rb +19 -19
  26. data/lib/pdk/cli/new/task.rb +23 -23
  27. data/lib/pdk/cli/new/test.rb +50 -48
  28. data/lib/pdk/cli/new/transport.rb +18 -18
  29. data/lib/pdk/cli/new.rb +11 -9
  30. data/lib/pdk/cli/release/prep.rb +27 -25
  31. data/lib/pdk/cli/release/publish.rb +39 -37
  32. data/lib/pdk/cli/release.rb +152 -149
  33. data/lib/pdk/cli/remove/config.rb +63 -60
  34. data/lib/pdk/cli/remove.rb +15 -13
  35. data/lib/pdk/cli/set/config.rb +91 -89
  36. data/lib/pdk/cli/set.rb +15 -13
  37. data/lib/pdk/cli/test/unit.rb +71 -69
  38. data/lib/pdk/cli/test.rb +9 -7
  39. data/lib/pdk/cli/update.rb +33 -38
  40. data/lib/pdk/cli/util/command_redirector.rb +10 -1
  41. data/lib/pdk/cli/util/interview.rb +11 -4
  42. data/lib/pdk/cli/util/option_normalizer.rb +2 -4
  43. data/lib/pdk/cli/util/option_validator.rb +7 -9
  44. data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
  45. data/lib/pdk/cli/util.rb +32 -48
  46. data/lib/pdk/cli/validate.rb +98 -96
  47. data/lib/pdk/cli.rb +124 -120
  48. data/lib/pdk/config/ini_file.rb +4 -3
  49. data/lib/pdk/config/ini_file_setting.rb +6 -10
  50. data/lib/pdk/config/json.rb +1 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +5 -10
  52. data/lib/pdk/config/json_schema_setting.rb +3 -5
  53. data/lib/pdk/config/json_with_schema.rb +2 -4
  54. data/lib/pdk/config/namespace.rb +19 -13
  55. data/lib/pdk/config/setting.rb +5 -6
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +4 -4
  58. data/lib/pdk/config/yaml.rb +3 -8
  59. data/lib/pdk/config/yaml_with_schema.rb +4 -12
  60. data/lib/pdk/config.rb +47 -51
  61. data/lib/pdk/context/control_repo.rb +3 -2
  62. data/lib/pdk/context/module.rb +2 -2
  63. data/lib/pdk/context/none.rb +2 -2
  64. data/lib/pdk/context.rb +4 -5
  65. data/lib/pdk/control_repo.rb +3 -4
  66. data/lib/pdk/generate/defined_type.rb +3 -3
  67. data/lib/pdk/generate/fact.rb +3 -2
  68. data/lib/pdk/generate/function.rb +5 -4
  69. data/lib/pdk/generate/module.rb +91 -106
  70. data/lib/pdk/generate/provider.rb +5 -4
  71. data/lib/pdk/generate/puppet_class.rb +3 -3
  72. data/lib/pdk/generate/puppet_object.rb +9 -12
  73. data/lib/pdk/generate/task.rb +11 -10
  74. data/lib/pdk/generate/transport.rb +8 -7
  75. data/lib/pdk/generate.rb +1 -1
  76. data/lib/pdk/logger.rb +3 -2
  77. data/lib/pdk/module/build.rb +34 -49
  78. data/lib/pdk/module/convert.rb +13 -22
  79. data/lib/pdk/module/metadata.rb +53 -61
  80. data/lib/pdk/module/release.rb +19 -25
  81. data/lib/pdk/module/update.rb +4 -13
  82. data/lib/pdk/module/update_manager.rb +18 -25
  83. data/lib/pdk/module.rb +1 -1
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +12 -37
  86. data/lib/pdk/report.rb +4 -4
  87. data/lib/pdk/template/fetcher/git.rb +7 -8
  88. data/lib/pdk/template/fetcher/local.rb +1 -0
  89. data/lib/pdk/template/fetcher.rb +4 -2
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
  91. data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
  92. data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
  93. data/lib/pdk/template/renderer/v1.rb +1 -1
  94. data/lib/pdk/template/renderer.rb +1 -0
  95. data/lib/pdk/template/template_dir.rb +3 -3
  96. data/lib/pdk/template.rb +2 -6
  97. data/lib/pdk/tests/unit.rb +36 -25
  98. data/lib/pdk/util/bundler.rb +10 -14
  99. data/lib/pdk/util/changelog_generator.rb +15 -12
  100. data/lib/pdk/util/env.rb +1 -0
  101. data/lib/pdk/util/filesystem.rb +18 -17
  102. data/lib/pdk/util/git.rb +16 -21
  103. data/lib/pdk/util/json_finder.rb +7 -6
  104. data/lib/pdk/util/puppet_strings.rb +1 -1
  105. data/lib/pdk/util/puppet_version.rb +16 -67
  106. data/lib/pdk/util/ruby_version.rb +9 -13
  107. data/lib/pdk/util/template_uri.rb +17 -29
  108. data/lib/pdk/util/vendored_file.rb +5 -18
  109. data/lib/pdk/util/windows/api_types.rb +70 -64
  110. data/lib/pdk/util/windows/file.rb +31 -27
  111. data/lib/pdk/util/windows/process.rb +59 -61
  112. data/lib/pdk/util/windows/string.rb +19 -12
  113. data/lib/pdk/util.rb +12 -20
  114. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
  115. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
  116. data/lib/pdk/validate/external_command_validator.rb +6 -1
  117. data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
  118. data/lib/pdk/validate/invokable_validator.rb +30 -20
  119. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
  120. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
  121. data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
  122. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
  123. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
  124. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
  125. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
  126. data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
  127. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
  128. data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
  129. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
  130. data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
  131. data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
  132. data/lib/pdk/validate/validator.rb +4 -2
  133. data/lib/pdk/validate/validator_group.rb +6 -3
  134. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
  135. data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
  136. data/lib/pdk/validate.rb +6 -6
  137. data/lib/pdk/version.rb +2 -2
  138. data/lib/pdk.rb +12 -12
  139. metadata +27 -35
  140. data/lib/pdk/cli/config/get.rb +0 -26
  141. data/lib/pdk/cli/config.rb +0 -22
  142. data/lib/pdk/cli/module/build.rb +0 -12
  143. data/lib/pdk/cli/module/generate.rb +0 -47
  144. data/lib/pdk/cli/module.rb +0 -14
@@ -1,119 +1,121 @@
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 }
1
+ module PDK
2
+ module CLI
3
+ module Set
4
+ module Config
5
+ ALLOWED_TYPE_NAMES = ['array', 'boolean', 'number', 'string'].freeze
6
+
7
+ # :nocov:
8
+ def self.pretty_allowed_names
9
+ ALLOWED_TYPE_NAMES.map { |name| "'#{name}'" }.join(', ')
16
10
  end
11
+ # :nocov:
17
12
 
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
13
+ def self.transform_value(type_name, value)
14
+ normalized_name = type_name.downcase.strip
15
+ unless ALLOWED_TYPE_NAMES.include?(normalized_name)
16
+ raise PDK::CLI::ExitWithError, format('Unknown type %{type_name}. Expected one of %{allowed}', type_name: type_name, allowed: pretty_allowed_names)
17
+ end
23
18
 
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
19
+ # Short circuit string conversions as it's trivial
20
+ if normalized_name == 'string'
21
+ raise PDK::CLI::ExitWithError, format('An error occured converting \'%{value}\' into a %{type_name}', value: value.nil? ? 'nil' : value, type_name: type_name) unless value.is_a?(String)
22
+
23
+ return value
24
+ end
25
+
26
+ begin
27
+ case normalized_name
28
+ when 'array'
29
+ convert_to_array(value)
30
+ when 'boolean'
31
+ convert_to_boolean(value)
32
+ when 'number'
33
+ convert_to_number(value)
34
+ else
35
+ value
36
+ end
37
+ rescue ArgumentError, TypeError
38
+ raise PDK::CLI::ExitWithError, format('An error occured converting \'%{value}\' into a %{type_name}', value: value.nil? ? 'nil' : value, type_name: type_name)
34
39
  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
40
  end
38
- end
39
41
 
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
42
+ def self.convert_to_array(value)
43
+ return [] if value.nil?
45
44
 
46
- def self.convert_to_boolean(value)
47
- string_val = value.to_s.strip.downcase
45
+ value.is_a?(Array) ? value : [value]
46
+ end
47
+ private_class_method :convert_to_array
48
48
 
49
- return true if %w[yes true -1 1].include?(string_val)
50
- return false if %w[no false 0].include?(string_val)
49
+ def self.convert_to_boolean(value)
50
+ string_val = value.to_s.strip.downcase
51
51
 
52
- raise ArgumentError
53
- end
54
- private_class_method :convert_to_boolean
52
+ return true if ['yes', 'true', '-1', '1'].include?(string_val)
53
+ return false if ['no', 'false', '0'].include?(string_val)
55
54
 
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
55
+ raise ArgumentError
56
+ end
57
+ private_class_method :convert_to_boolean
58
+
59
+ def self.convert_to_number(value)
60
+ float_val = Float(value)
61
+ # Return an Integer if this is actually and Integer, otherwise return the float
62
+ float_val.truncate == float_val ? float_val.truncate : float_val
63
+ end
64
+ private_class_method :convert_to_number
62
65
 
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
+ def self.run(opts, args)
67
+ item_name = args.count.positive? ? args[0] : nil
68
+ item_value = args.count > 1 ? args[1] : nil
66
69
 
67
- opts[:type] = opts[:as] if opts[:type].nil? && !opts[:as].nil?
68
- force = opts[:force] || false
70
+ opts[:type] = opts[:as] if opts[:type].nil? && !opts[:as].nil?
71
+ force = opts[:force] || false
69
72
 
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?
73
+ # Transform the value if we need to
74
+ item_value = PDK::CLI::Set::Config.transform_value(opts[:type], item_value) unless opts[:type].nil?
72
75
 
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?
76
+ raise PDK::CLI::ExitWithError, 'Configuration name is required' if item_name.nil?
77
+ raise PDK::CLI::ExitWithError, 'Configuration value is required. If you wish to remove a value use \'pdk remove config\'' if item_value.nil?
75
78
 
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)
79
+ current_value = PDK.config.get(item_name)
80
+ raise PDK::CLI::ExitWithError, format("The configuration item '%{name}' can not have a value set.", name: item_name) if current_value.is_a?(PDK::Config::Namespace)
78
81
 
79
- # If we're forcing the value, don't do any munging
80
- unless force
82
+ # If we're forcing the value, don't do any munging
81
83
  # 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
+ if !force && (current_value.is_a?(Array) && current_value.include?(item_value))
85
+ PDK.logger.info(format("No changes made to '%{name}' as it already contains value '%{to}'", name: item_name, to: item_value))
84
86
  return 0
85
87
  end
86
- end
87
88
 
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
89
+ new_value = PDK.config.set(item_name, item_value, force: opts[:force])
90
+ if current_value.nil? || force
91
+ PDK.logger.info(format("Set initial value of '%{name}' to '%{to}'", name: item_name, to: new_value))
92
+ elsif current_value.is_a?(Array)
93
+ # Arrays have a special output format
94
+ PDK.logger.info(format("Added new value '%{to}' to '%{name}'", name: item_name, to: item_value))
95
+ else
96
+ PDK.logger.info(format("Changed existing value of '%{name}' from '%{from}' to '%{to}'", name: item_name, from: current_value, to: new_value))
97
+ end
97
98
 
98
- # Same output as `get config`
99
- $stdout.puts '%{name}=%{value}' % { name: item_name, value: PDK.config.get(item_name) }
100
- 0
99
+ # Same output as `get config`
100
+ $stdout.puts format('%{name}=%{value}', name: item_name, value: PDK.config.get(item_name))
101
+ 0
102
+ end
101
103
  end
102
104
  end
103
- end
104
105
 
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>'
106
+ @set_config_cmd = @set_cmd.define_command do
107
+ name 'config'
108
+ usage 'config [name] [value]'
109
+ summary 'Set or update the configuration for <name>'
109
110
 
110
- option :f, :force, 'Force the configuration setting to be overwitten.', argument: :forbidden
111
+ option :f, :force, 'Force the configuration setting to be overwitten.', argument: :forbidden
111
112
 
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
113
+ option :t, :type, format('The type of value to set. Acceptable values: %{values}', values: PDK::CLI::Set::Config.pretty_allowed_names), argument: :required
114
+ option nil, :as, 'Alias of --type', argument: :required
114
115
 
115
- run do |opts, args, _cmd|
116
- exit PDK::CLI::Set::Config.run(opts, args)
116
+ run do |opts, args, _cmd|
117
+ exit PDK::CLI::Set::Config.run(opts, args)
118
+ end
117
119
  end
118
120
  end
119
121
  end
data/lib/pdk/cli/set.rb CHANGED
@@ -1,20 +1,22 @@
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'
1
+ module PDK
2
+ module CLI
3
+ @set_cmd = @base_cmd.define_command do
4
+ name 'set'
5
+ usage 'set [subcommand] [options]'
6
+ summary 'Set or update information about the PDK or current project.'
7
+ default_subcommand 'help'
7
8
 
8
- run do |_opts, args, _cmd|
9
- if args == ['help']
10
- PDK::CLI.run(%w[set --help])
11
- exit 0
12
- end
9
+ run do |_opts, args, _cmd|
10
+ if args == ['help']
11
+ PDK::CLI.run(['set', '--help'])
12
+ exit 0
13
+ end
13
14
 
14
- PDK::CLI.run(%w[set help]) if args.empty?
15
+ PDK::CLI.run(['set', 'help']) if args.empty?
16
+ end
15
17
  end
18
+ @set_cmd.add_command Cri::Command.new_basic_help
16
19
  end
17
- @set_cmd.add_command Cri::Command.new_basic_help
18
20
  end
19
21
 
20
22
  require 'pdk/cli/set/config'
@@ -1,89 +1,91 @@
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
1
+ module PDK
2
+ module CLI
3
+ @test_unit_cmd = @test_cmd.define_command do
4
+ name 'unit'
5
+ usage 'unit [options]'
6
+ summary 'Run unit tests.'
7
+
8
+ PDK::CLI.puppet_version_options(self)
9
+ PDK::CLI.puppet_dev_option(self)
10
+ flag nil, :list, 'List all available unit test files.'
11
+ flag nil, :parallel, 'Run unit tests in parallel.'
12
+ flag :v, :verbose, 'More verbose --list output. Displays a list of examples in each unit test file.'
13
+ flag :c, 'clean-fixtures', 'Clean up downloaded fixtures after the test run.'
14
+
15
+ option nil, :tests, 'Specify a comma-separated list of unit test files to run.', argument: :required, default: '' do |values|
16
+ require 'pdk/cli/util/option_validator'
17
+ PDK::CLI::Util::OptionValidator.comma_separated_list?(values)
18
+ end
18
19
 
19
- # TODO
20
- # option nil, :runner_options, "options to pass through to the actual test-runner", argument: :required
20
+ # TODO
21
+ # option nil, :runner_options, "options to pass through to the actual test-runner", argument: :required
21
22
 
22
- run do |opts, _args, _cmd|
23
- require 'pdk/tests/unit'
24
- require 'pdk/report'
25
- require 'pdk/util/bundler'
23
+ run do |opts, _args, _cmd|
24
+ require 'pdk/tests/unit'
25
+ require 'pdk/report'
26
+ require 'pdk/util/bundler'
26
27
 
27
- PDK::CLI::Util.validate_puppet_version_opts(opts)
28
+ PDK::CLI::Util.validate_puppet_version_opts(opts)
28
29
 
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
- )
30
+ PDK::CLI::Util.ensure_in_module!(
31
+ message: 'Unit tests can only be run from inside a valid module directory.',
32
+ log_level: :info
33
+ )
33
34
 
34
- PDK::CLI::Util.module_version_check
35
+ PDK::CLI::Util.module_version_check
35
36
 
36
- PDK::CLI::Util.analytics_screen_view('test_unit', opts)
37
+ PDK::CLI::Util.analytics_screen_view('test_unit', opts)
37
38
 
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])
39
+ # Ensure that the bundled gems are up to date and correct Ruby is activated before running or listing tests.
40
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
41
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
41
42
 
42
- opts.merge!(puppet_env[:gemset])
43
+ opts.merge!(puppet_env[:gemset])
43
44
 
44
- PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
45
+ PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
45
46
 
46
- report = nil
47
+ report = nil
47
48
 
48
- if opts[:list]
49
- examples = PDK::Test::Unit.list(opts)
49
+ if opts[:list]
50
+ examples = PDK::Test::Unit.list(opts)
50
51
 
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
52
+ if examples.empty?
53
+ puts 'No unit test files with examples were found.'
54
+ else
55
+ puts 'Unit Test Files:'
56
+ files = examples.map { |example| example[:file_path] }
57
+ files.uniq.each do |file|
58
+ puts file
58
59
 
59
- next unless opts[:verbose]
60
+ next unless opts[:verbose]
60
61
 
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] }
62
+ file_examples = examples.select { |example| example[:file_path] == file }
63
+ file_examples.each do |file_example|
64
+ puts format("\t%{id}\t%{description}", id: file_example[:id], description: file_example[:full_description])
65
+ end
64
66
  end
65
67
  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
68
+ else
69
+ report = PDK::Report.new
70
+ report_formats = if opts[:format]
71
+ opts[:interactive] = false
72
+ PDK::CLI::Util::OptionNormalizer.report_formats(opts[:format])
73
+ else
74
+ opts[:interactive] = true
75
+ [{
76
+ method: PDK::Report.default_format,
77
+ target: PDK::Report.default_target
78
+ }]
79
+ end
80
+
81
+ exit_code = PDK::Test::Unit.invoke(report, opts)
82
+
83
+ report_formats.each do |format|
84
+ report.send(format[:method], format[:target])
85
+ end
85
86
 
86
- exit exit_code
87
+ exit exit_code
88
+ end
87
89
  end
88
90
  end
89
91
  end
data/lib/pdk/cli/test.rb CHANGED
@@ -1,11 +1,13 @@
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'
1
+ module PDK
2
+ module CLI
3
+ @test_cmd = @base_cmd.define_command do
4
+ name 'test'
5
+ usage 'test [subcommand] [options]'
6
+ summary 'Run tests.'
7
+ default_subcommand 'help'
8
+ end
9
+ @test_cmd.add_command Cri::Command.new_basic_help
7
10
  end
8
- @test_cmd.add_command Cri::Command.new_basic_help
9
11
  end
10
12
 
11
13
  require 'pdk/cli/test/unit'
@@ -1,54 +1,49 @@
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.'
1
+ module PDK
2
+ module CLI
3
+ @update_cmd = @base_cmd.define_command do
4
+ name 'update'
5
+ usage 'update [options]'
6
+ summary 'Update a module that has been created by or converted for use by PDK.'
6
7
 
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.'
8
+ flag nil, :noop, 'Do not update the module, just output what would be done.'
9
+ flag nil, :force, 'Update the module automatically, with no prompts.'
9
10
 
10
- PDK::CLI.template_ref_option(self)
11
+ PDK::CLI.template_ref_option(self)
11
12
 
12
- run do |opts, _args, _cmd|
13
- # Write the context information to the debug log
14
- PDK.context.to_debug_log
13
+ run do |opts, _args, _cmd|
14
+ # Write the context information to the debug log
15
+ PDK.context.to_debug_log
15
16
 
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
17
+ raise PDK::CLI::ExitWithError, '`pdk update` can only be run from inside a valid module directory.' unless PDK.context.is_a?(PDK::Context::Module)
19
18
 
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?
19
+ 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
20
 
22
- if opts[:noop] && opts[:force]
23
- raise PDK::CLI::ExitWithError, 'You can not specify --noop and --force when updating a module'
24
- end
21
+ raise PDK::CLI::ExitWithError, 'You can not specify --noop and --force when updating a module' if opts[:noop] && opts[:force]
25
22
 
26
- if Gem::Version.new(PDK::VERSION) < Gem::Version.new(PDK::Util.module_pdk_version)
27
- PDK.logger.warn "This module has been updated to PDK #{PDK::Util.module_pdk_version} which is newer than your PDK version (#{PDK::VERSION}), proceed with caution!"
23
+ if Gem::Version.new(PDK::VERSION) < Gem::Version.new(PDK::Util.module_pdk_version)
24
+ PDK.logger.warn "This module has been updated to PDK #{PDK::Util.module_pdk_version} which is newer than your PDK version (#{PDK::VERSION}), proceed with caution!"
28
25
 
29
- unless opts[:force]
30
- raise PDK::CLI::ExitWithError,
31
- 'Please update your PDK installation and try again. ' \
32
- 'You may also use the --force flag to override this and ' \
33
- 'continue at your own risk.'
26
+ unless opts[:force]
27
+ raise PDK::CLI::ExitWithError,
28
+ 'Please update your PDK installation and try again. ' \
29
+ 'You may also use the --force flag to override this and ' \
30
+ 'continue at your own risk.'
31
+ end
34
32
  end
35
- end
36
33
 
37
- PDK::CLI::Util.analytics_screen_view('update', opts)
34
+ PDK::CLI::Util.analytics_screen_view('update', opts)
38
35
 
39
- updater = PDK::Module::Update.new(PDK.context.root_path, opts)
36
+ updater = PDK::Module::Update.new(PDK.context.root_path, opts)
40
37
 
41
- if updater.pinned_to_puppetlabs_template_tag?
42
- PDK.logger.info 'This module is currently pinned to version %{current_version} ' \
43
- 'of the default template. If you would like to update your ' \
44
- 'module to the latest version of the template, please run `pdk ' \
45
- 'update --template-ref %{new_version}`.' % {
46
- current_version: updater.template_uri.uri_fragment,
47
- new_version: PDK::TEMPLATE_REF,
48
- }
49
- end
38
+ if updater.pinned_to_puppetlabs_template_tag?
39
+ PDK.logger.info format('This module is currently pinned to version %{current_version} ' \
40
+ 'of the default template. If you would like to update your ' \
41
+ 'module to the latest version of the template, please run `pdk ' \
42
+ 'update --template-ref %{new_version}`.', current_version: updater.template_uri.uri_fragment, new_version: PDK::TEMPLATE_REF)
43
+ end
50
44
 
51
- updater.run
45
+ updater.run
46
+ end
52
47
  end
53
48
  end
54
49
  end
@@ -7,6 +7,15 @@ module PDK
7
7
  class CommandRedirector < TTY::Prompt::AnswersCollector
8
8
  attr_accessor :command
9
9
 
10
+ # Override the initialize method because the original one
11
+ # doesn't work with Ruby 3.
12
+ # rubocop:disable Lint/MissingSuper
13
+ def initialize(prompt, options = {})
14
+ @prompt = prompt
15
+ @answers = options.fetch(:answers) { {} }
16
+ end
17
+ # rubocop:enable Lint/MissingSuper
18
+
10
19
  def pastel
11
20
  @pastel ||= Pastel.new
12
21
  end
@@ -16,7 +25,7 @@ module PDK
16
25
  end
17
26
 
18
27
  def run
19
- @prompt.puts 'Did you mean \'%{command}\'?' % { command: pastel.bold(@command) }
28
+ @prompt.puts "Did you mean '#{pastel.bold(@command)}'?"
20
29
  @prompt.yes?('-->')
21
30
  rescue PDK::CLI::Util::Interview::READER::InputInterrupt
22
31
  nil
@@ -7,6 +7,15 @@ module PDK
7
7
  class Interview < TTY::Prompt::AnswersCollector
8
8
  READER = defined?(TTY::Reader) ? TTY::Reader : TTY::Prompt::Reader
9
9
 
10
+ # Override the initialize method because the original one
11
+ # doesn't work with Ruby 3.
12
+ # rubocop:disable Lint/MissingSuper
13
+ def initialize(prompt, options = {})
14
+ @prompt = prompt
15
+ @answers = options.fetch(:answers) { {} }
16
+ end
17
+ # rubocop:enable Lint/MissingSuper
18
+
10
19
  def pastel
11
20
  @pastel ||= Pastel.new
12
21
  end
@@ -30,7 +39,7 @@ module PDK
30
39
  num_questions = @questions.count
31
40
  @questions.each do |question_name, question|
32
41
  @name = question_name
33
- @prompt.print pastel.bold('[Q %{current_number}/%{questions_total}]' % { current_number: i, questions_total: num_questions }) + ' '
42
+ @prompt.print "#{pastel.bold(format('[Q %{current_number}/%{questions_total}]', current_number: i, questions_total: num_questions))} "
34
43
  @prompt.puts pastel.bold(question[:question])
35
44
  @prompt.puts question[:help] if question.key?(:help)
36
45
 
@@ -52,9 +61,7 @@ module PDK
52
61
  ask('-->') do |q|
53
62
  q.required(question.fetch(:required, false))
54
63
 
55
- if question.key?(:validate_pattern)
56
- q.validate(question[:validate_pattern], question[:validate_message])
57
- end
64
+ q.validate(question[:validate_pattern], question[:validate_message]) if question.key?(:validate_pattern)
58
65
 
59
66
  q.default(question[:default]) if question.key?(:default)
60
67
  end
@@ -6,6 +6,7 @@ module PDK
6
6
  class OptionNormalizer
7
7
  def self.comma_separated_list_to_array(list, _options = {})
8
8
  raise 'Error: expected comma separated list' unless OptionValidator.comma_separated_list?(list)
9
+
9
10
  list.split(',').compact
10
11
  end
11
12
 
@@ -31,10 +32,7 @@ module PDK
31
32
  begin
32
33
  OptionValidator.enum(format, PDK::Report.formats)
33
34
  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
- }
35
+ raise PDK::CLI::ExitWithError, format("'%{name}' is not a valid report format (%{valid})", name: format, valid: PDK::Report.formats.join(', '))
38
36
  end
39
37
 
40
38
  case target