pdk 2.7.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/README.md +2 -48
- data/lib/pdk/analytics/client/google_analytics.rb +22 -26
- data/lib/pdk/analytics/util.rb +0 -1
- data/lib/pdk/analytics.rb +1 -1
- data/lib/pdk/bolt.rb +1 -0
- data/lib/pdk/cli/build.rb +53 -56
- data/lib/pdk/cli/bundle.rb +34 -33
- data/lib/pdk/cli/console.rb +136 -134
- data/lib/pdk/cli/convert.rb +39 -41
- data/lib/pdk/cli/env.rb +49 -47
- data/lib/pdk/cli/errors.rb +1 -2
- data/lib/pdk/cli/exec/command.rb +23 -29
- data/lib/pdk/cli/exec/interactive_command.rb +7 -12
- data/lib/pdk/cli/exec.rb +4 -11
- data/lib/pdk/cli/exec_group.rb +3 -2
- data/lib/pdk/cli/get/config.rb +21 -19
- data/lib/pdk/cli/get.rb +15 -13
- data/lib/pdk/cli/new/class.rb +22 -22
- data/lib/pdk/cli/new/defined_type.rb +22 -22
- data/lib/pdk/cli/new/fact.rb +19 -19
- data/lib/pdk/cli/new/function.rb +20 -20
- data/lib/pdk/cli/new/module.rb +40 -38
- data/lib/pdk/cli/new/provider.rb +19 -19
- data/lib/pdk/cli/new/task.rb +23 -23
- data/lib/pdk/cli/new/test.rb +50 -48
- data/lib/pdk/cli/new/transport.rb +18 -18
- data/lib/pdk/cli/new.rb +11 -9
- data/lib/pdk/cli/release/prep.rb +27 -25
- data/lib/pdk/cli/release/publish.rb +39 -37
- data/lib/pdk/cli/release.rb +152 -149
- data/lib/pdk/cli/remove/config.rb +63 -60
- data/lib/pdk/cli/remove.rb +15 -13
- data/lib/pdk/cli/set/config.rb +91 -89
- data/lib/pdk/cli/set.rb +15 -13
- data/lib/pdk/cli/test/unit.rb +71 -69
- data/lib/pdk/cli/test.rb +9 -7
- data/lib/pdk/cli/update.rb +33 -38
- data/lib/pdk/cli/util/command_redirector.rb +10 -1
- data/lib/pdk/cli/util/interview.rb +11 -4
- data/lib/pdk/cli/util/option_normalizer.rb +2 -4
- data/lib/pdk/cli/util/option_validator.rb +7 -9
- data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
- data/lib/pdk/cli/util.rb +32 -48
- data/lib/pdk/cli/validate.rb +98 -96
- data/lib/pdk/cli.rb +124 -120
- data/lib/pdk/config/ini_file.rb +4 -3
- data/lib/pdk/config/ini_file_setting.rb +6 -10
- data/lib/pdk/config/json.rb +1 -0
- data/lib/pdk/config/json_schema_namespace.rb +5 -10
- data/lib/pdk/config/json_schema_setting.rb +3 -5
- data/lib/pdk/config/json_with_schema.rb +2 -4
- data/lib/pdk/config/namespace.rb +19 -13
- data/lib/pdk/config/setting.rb +5 -6
- data/lib/pdk/config/task_schema.json +116 -0
- data/lib/pdk/config/validator.rb +4 -4
- data/lib/pdk/config/yaml.rb +3 -8
- data/lib/pdk/config/yaml_with_schema.rb +4 -12
- data/lib/pdk/config.rb +47 -51
- data/lib/pdk/context/control_repo.rb +3 -2
- data/lib/pdk/context/module.rb +2 -2
- data/lib/pdk/context/none.rb +2 -2
- data/lib/pdk/context.rb +4 -5
- data/lib/pdk/control_repo.rb +3 -4
- data/lib/pdk/generate/defined_type.rb +3 -3
- data/lib/pdk/generate/fact.rb +3 -2
- data/lib/pdk/generate/function.rb +5 -4
- data/lib/pdk/generate/module.rb +91 -106
- data/lib/pdk/generate/provider.rb +5 -4
- data/lib/pdk/generate/puppet_class.rb +3 -3
- data/lib/pdk/generate/puppet_object.rb +9 -12
- data/lib/pdk/generate/task.rb +11 -10
- data/lib/pdk/generate/transport.rb +8 -7
- data/lib/pdk/generate.rb +1 -1
- data/lib/pdk/logger.rb +3 -2
- data/lib/pdk/module/build.rb +34 -49
- data/lib/pdk/module/convert.rb +13 -22
- data/lib/pdk/module/metadata.rb +53 -61
- data/lib/pdk/module/release.rb +19 -25
- data/lib/pdk/module/update.rb +4 -13
- data/lib/pdk/module/update_manager.rb +18 -25
- data/lib/pdk/module.rb +1 -1
- data/lib/pdk/monkey_patches.rb +268 -0
- data/lib/pdk/report/event.rb +12 -37
- data/lib/pdk/report.rb +4 -4
- data/lib/pdk/template/fetcher/git.rb +7 -8
- data/lib/pdk/template/fetcher/local.rb +1 -0
- data/lib/pdk/template/fetcher.rb +4 -2
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
- data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
- data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
- data/lib/pdk/template/renderer/v1.rb +1 -1
- data/lib/pdk/template/renderer.rb +1 -0
- data/lib/pdk/template/template_dir.rb +3 -3
- data/lib/pdk/template.rb +2 -6
- data/lib/pdk/tests/unit.rb +36 -25
- data/lib/pdk/util/bundler.rb +10 -14
- data/lib/pdk/util/changelog_generator.rb +15 -12
- data/lib/pdk/util/env.rb +1 -0
- data/lib/pdk/util/filesystem.rb +18 -17
- data/lib/pdk/util/git.rb +16 -21
- data/lib/pdk/util/json_finder.rb +7 -6
- data/lib/pdk/util/puppet_strings.rb +1 -1
- data/lib/pdk/util/puppet_version.rb +16 -67
- data/lib/pdk/util/ruby_version.rb +9 -13
- data/lib/pdk/util/template_uri.rb +17 -29
- data/lib/pdk/util/vendored_file.rb +5 -18
- data/lib/pdk/util/windows/api_types.rb +70 -64
- data/lib/pdk/util/windows/file.rb +31 -27
- data/lib/pdk/util/windows/process.rb +59 -61
- data/lib/pdk/util/windows/string.rb +19 -12
- data/lib/pdk/util.rb +12 -20
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
- data/lib/pdk/validate/external_command_validator.rb +6 -1
- data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
- data/lib/pdk/validate/invokable_validator.rb +30 -20
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
- data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
- data/lib/pdk/validate/validator.rb +4 -2
- data/lib/pdk/validate/validator_group.rb +6 -3
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
- data/lib/pdk/validate.rb +6 -6
- data/lib/pdk/version.rb +2 -2
- data/lib/pdk.rb +12 -12
- metadata +27 -35
- data/lib/pdk/cli/config/get.rb +0 -26
- data/lib/pdk/cli/config.rb +0 -22
- data/lib/pdk/cli/module/build.rb +0 -12
- data/lib/pdk/cli/module/generate.rb +0 -47
- data/lib/pdk/cli/module.rb +0 -14
data/lib/pdk/cli/set/config.rb
CHANGED
@@ -1,119 +1,121 @@
|
|
1
|
-
module PDK
|
2
|
-
module
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
41
|
-
|
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
|
-
|
47
|
-
|
45
|
+
value.is_a?(Array) ? value : [value]
|
46
|
+
end
|
47
|
+
private_class_method :convert_to_array
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
def self.convert_to_boolean(value)
|
50
|
+
string_val = value.to_s.strip.downcase
|
51
51
|
|
52
|
-
|
53
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
68
|
-
|
70
|
+
opts[:type] = opts[:as] if opts[:type].nil? && !opts[:as].nil?
|
71
|
+
force = opts[:force] || false
|
69
72
|
|
70
|
-
|
71
|
-
|
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
|
-
|
74
|
-
|
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
|
-
|
77
|
-
|
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
|
-
|
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}'"
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
111
|
+
option :f, :force, 'Force the configuration setting to be overwitten.', argument: :forbidden
|
111
112
|
|
112
|
-
|
113
|
-
|
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
|
-
|
116
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
run do |_opts, args, _cmd|
|
10
|
+
if args == ['help']
|
11
|
+
PDK::CLI.run(['set', '--help'])
|
12
|
+
exit 0
|
13
|
+
end
|
13
14
|
|
14
|
-
|
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'
|
data/lib/pdk/cli/test/unit.rb
CHANGED
@@ -1,89 +1,91 @@
|
|
1
|
-
module PDK
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
20
|
+
# TODO
|
21
|
+
# option nil, :runner_options, "options to pass through to the actual test-runner", argument: :required
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
run do |opts, _args, _cmd|
|
24
|
+
require 'pdk/tests/unit'
|
25
|
+
require 'pdk/report'
|
26
|
+
require 'pdk/util/bundler'
|
26
27
|
|
27
|
-
|
28
|
+
PDK::CLI::Util.validate_puppet_version_opts(opts)
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
35
|
+
PDK::CLI::Util.module_version_check
|
35
36
|
|
36
|
-
|
37
|
+
PDK::CLI::Util.analytics_screen_view('test_unit', opts)
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
+
opts.merge!(puppet_env[:gemset])
|
43
44
|
|
44
|
-
|
45
|
+
PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
|
45
46
|
|
46
|
-
|
47
|
+
report = nil
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
if opts[:list]
|
50
|
+
examples = PDK::Test::Unit.list(opts)
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
60
|
+
next unless opts[:verbose]
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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'
|
data/lib/pdk/cli/update.rb
CHANGED
@@ -1,54 +1,49 @@
|
|
1
|
-
module PDK
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
8
|
-
|
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
|
-
|
11
|
+
PDK::CLI.template_ref_option(self)
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
run do |opts, _args, _cmd|
|
14
|
+
# Write the context information to the debug log
|
15
|
+
PDK.context.to_debug_log
|
15
16
|
|
16
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
34
|
+
PDK::CLI::Util.analytics_screen_view('update', opts)
|
38
35
|
|
39
|
-
|
36
|
+
updater = PDK::Module::Update.new(PDK.context.root_path, opts)
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
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}]'
|
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
|