pdk 2.6.1 → 2.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -1
- data/lib/pdk/analytics/client/google_analytics.rb +4 -2
- data/lib/pdk/cli/build.rb +17 -21
- data/lib/pdk/cli/bundle.rb +4 -5
- data/lib/pdk/cli/config/get.rb +6 -6
- data/lib/pdk/cli/config.rb +3 -3
- data/lib/pdk/cli/console.rb +7 -7
- data/lib/pdk/cli/convert.rb +11 -11
- data/lib/pdk/cli/env.rb +3 -4
- data/lib/pdk/cli/errors.rb +1 -1
- data/lib/pdk/cli/exec/command.rb +12 -14
- data/lib/pdk/cli/exec/interactive_command.rb +11 -11
- data/lib/pdk/cli/exec.rb +4 -4
- data/lib/pdk/cli/exec_group.rb +1 -3
- data/lib/pdk/cli/get/config.rb +5 -5
- data/lib/pdk/cli/get.rb +2 -2
- data/lib/pdk/cli/module/build.rb +3 -3
- data/lib/pdk/cli/module/generate.rb +4 -4
- data/lib/pdk/cli/module.rb +3 -3
- data/lib/pdk/cli/new/class.rb +4 -4
- data/lib/pdk/cli/new/defined_type.rb +4 -4
- data/lib/pdk/cli/new/fact.rb +3 -3
- data/lib/pdk/cli/new/function.rb +4 -4
- data/lib/pdk/cli/new/module.rb +10 -11
- data/lib/pdk/cli/new/provider.rb +3 -3
- data/lib/pdk/cli/new/task.rb +5 -5
- data/lib/pdk/cli/new/test.rb +7 -7
- data/lib/pdk/cli/new/transport.rb +3 -3
- data/lib/pdk/cli/new.rb +3 -3
- data/lib/pdk/cli/release/prep.rb +9 -9
- data/lib/pdk/cli/release/publish.rb +7 -11
- data/lib/pdk/cli/release.rb +35 -39
- data/lib/pdk/cli/remove/config.rb +15 -15
- data/lib/pdk/cli/remove.rb +2 -2
- data/lib/pdk/cli/set/config.rb +16 -16
- data/lib/pdk/cli/set.rb +2 -2
- data/lib/pdk/cli/test/unit.rb +13 -13
- data/lib/pdk/cli/test.rb +2 -2
- data/lib/pdk/cli/update.rb +19 -29
- data/lib/pdk/cli/util/command_redirector.rb +1 -1
- data/lib/pdk/cli/util/interview.rb +4 -4
- data/lib/pdk/cli/util/option_normalizer.rb +2 -2
- data/lib/pdk/cli/util/option_validator.rb +1 -1
- data/lib/pdk/cli/util.rb +19 -20
- data/lib/pdk/cli/validate.rb +16 -18
- data/lib/pdk/cli.rb +16 -33
- data/lib/pdk/config/ini_file_setting.rb +2 -2
- data/lib/pdk/config/json_schema_namespace.rb +3 -3
- data/lib/pdk/config/json_schema_setting.rb +1 -1
- data/lib/pdk/config/json_with_schema.rb +1 -1
- data/lib/pdk/config/namespace.rb +4 -4
- data/lib/pdk/config/setting.rb +5 -5
- data/lib/pdk/config/validator.rb +2 -2
- data/lib/pdk/config/yaml.rb +2 -2
- data/lib/pdk/config/yaml_with_schema.rb +3 -3
- data/lib/pdk/config.rb +18 -20
- data/lib/pdk/context/control_repo.rb +1 -1
- data/lib/pdk/context/module.rb +1 -1
- data/lib/pdk/context/none.rb +1 -1
- data/lib/pdk/generate/module.rb +52 -64
- data/lib/pdk/generate/puppet_object.rb +6 -6
- data/lib/pdk/generate/task.rb +1 -1
- data/lib/pdk/module/build.rb +11 -16
- data/lib/pdk/module/convert.rb +14 -16
- data/lib/pdk/module/metadata.rb +12 -12
- data/lib/pdk/module/release.rb +20 -19
- data/lib/pdk/module/update.rb +5 -5
- data/lib/pdk/module/update_manager.rb +6 -6
- data/lib/pdk/report/event.rb +11 -11
- data/lib/pdk/template/fetcher/git.rb +4 -4
- data/lib/pdk/template/fetcher.rb +1 -1
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +1 -1
- data/lib/pdk/template/renderer/v1/renderer.rb +5 -7
- data/lib/pdk/template/renderer/v1/template_file.rb +3 -1
- data/lib/pdk/template/template_dir.rb +1 -1
- data/lib/pdk/template.rb +2 -2
- data/lib/pdk/tests/unit.rb +12 -12
- data/lib/pdk/util/bundler.rb +14 -14
- data/lib/pdk/util/changelog_generator.rb +6 -8
- data/lib/pdk/util/filesystem.rb +2 -2
- data/lib/pdk/util/git.rb +5 -5
- data/lib/pdk/util/puppet_strings.rb +2 -2
- data/lib/pdk/util/puppet_version.rb +24 -17
- data/lib/pdk/util/ruby_version.rb +2 -5
- data/lib/pdk/util/template_uri.rb +8 -8
- data/lib/pdk/util/vendored_file.rb +3 -3
- data/lib/pdk/util/windows/api_types.rb +3 -4
- data/lib/pdk/util/windows/file.rb +1 -1
- data/lib/pdk/util/windows/process.rb +5 -8
- data/lib/pdk/util.rb +2 -2
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +5 -5
- data/lib/pdk/validate/invokable_validator.rb +6 -6
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +2 -2
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +2 -2
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +38 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +1 -1
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +4 -4
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +2 -5
- data/lib/pdk/validate/validator.rb +1 -1
- data/lib/pdk/validate/validator_group.rb +1 -1
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +4 -4
- data/lib/pdk/validate.rb +2 -1
- data/lib/pdk/version.rb +2 -2
- data/lib/pdk.rb +0 -2
- metadata +32 -54
- data/lib/pdk/i18n.rb +0 -4
- data/locales/config.yaml +0 -21
- data/locales/pdk.pot +0 -2111
data/lib/pdk/cli/remove.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module PDK::CLI
|
|
2
2
|
@remove_cmd = @base_cmd.define_command do
|
|
3
3
|
name 'remove'
|
|
4
|
-
usage
|
|
5
|
-
summary
|
|
4
|
+
usage 'remove [subcommand] [options]'
|
|
5
|
+
summary 'Remove or delete information about the PDK or current project.'
|
|
6
6
|
default_subcommand 'help'
|
|
7
7
|
|
|
8
8
|
run do |_opts, args, _cmd|
|
data/lib/pdk/cli/set/config.rb
CHANGED
|
@@ -12,12 +12,12 @@ module PDK::CLI
|
|
|
12
12
|
def self.transform_value(type_name, value)
|
|
13
13
|
normalized_name = type_name.downcase.strip
|
|
14
14
|
unless ALLOWED_TYPE_NAMES.include?(normalized_name)
|
|
15
|
-
raise PDK::CLI::ExitWithError,
|
|
15
|
+
raise PDK::CLI::ExitWithError, 'Unknown type %{type_name}. Expected one of %{allowed}' % { type_name: type_name, allowed: pretty_allowed_names }
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
# Short circuit string conversions as it's trivial
|
|
19
19
|
if normalized_name == 'string'
|
|
20
|
-
raise PDK::CLI::ExitWithError,
|
|
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
21
|
return value
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -33,7 +33,7 @@ module PDK::CLI
|
|
|
33
33
|
value
|
|
34
34
|
end
|
|
35
35
|
rescue ArgumentError, TypeError
|
|
36
|
-
raise PDK::CLI::ExitWithError,
|
|
36
|
+
raise PDK::CLI::ExitWithError, 'An error occured converting \'%{value}\' into a %{type_name}' % { value: value.nil? ? 'nil' : value, type_name: type_name }
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -70,33 +70,33 @@ module PDK::CLI
|
|
|
70
70
|
# Transform the value if we need to
|
|
71
71
|
item_value = PDK::CLI::Set::Config.transform_value(opts[:type], item_value) unless opts[:type].nil?
|
|
72
72
|
|
|
73
|
-
raise PDK::CLI::ExitWithError,
|
|
74
|
-
raise PDK::CLI::ExitWithError,
|
|
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
75
|
|
|
76
76
|
current_value = PDK.config.get(item_name)
|
|
77
|
-
raise PDK::CLI::ExitWithError,
|
|
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
78
|
|
|
79
79
|
# If we're forcing the value, don't do any munging
|
|
80
80
|
unless force
|
|
81
81
|
# Check if the setting already exists
|
|
82
82
|
if current_value.is_a?(Array) && current_value.include?(item_value)
|
|
83
|
-
PDK.logger.info(
|
|
83
|
+
PDK.logger.info("No changes made to '%{name}' as it already contains value '%{to}'" % { name: item_name, to: item_value })
|
|
84
84
|
return 0
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
new_value = PDK.config.set(item_name, item_value, force: opts[:force])
|
|
89
89
|
if current_value.nil? || force
|
|
90
|
-
PDK.logger.info(
|
|
90
|
+
PDK.logger.info("Set initial value of '%{name}' to '%{to}'" % { name: item_name, to: new_value })
|
|
91
91
|
elsif current_value.is_a?(Array)
|
|
92
92
|
# Arrays have a special output format
|
|
93
|
-
PDK.logger.info(
|
|
93
|
+
PDK.logger.info("Added new value '%{to}' to '%{name}'" % { name: item_name, to: item_value })
|
|
94
94
|
else
|
|
95
|
-
PDK.logger.info(
|
|
95
|
+
PDK.logger.info("Changed existing value of '%{name}' from '%{from}' to '%{to}'" % { name: item_name, from: current_value, to: new_value })
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
# Same output as `get config`
|
|
99
|
-
$stdout.puts
|
|
99
|
+
$stdout.puts '%{name}=%{value}' % { name: item_name, value: PDK.config.get(item_name) }
|
|
100
100
|
0
|
|
101
101
|
end
|
|
102
102
|
end
|
|
@@ -104,13 +104,13 @@ module PDK::CLI
|
|
|
104
104
|
|
|
105
105
|
@set_config_cmd = @set_cmd.define_command do
|
|
106
106
|
name 'config'
|
|
107
|
-
usage
|
|
108
|
-
summary
|
|
107
|
+
usage 'config [name] [value]'
|
|
108
|
+
summary 'Set or update the configuration for <name>'
|
|
109
109
|
|
|
110
|
-
option :f, :force,
|
|
110
|
+
option :f, :force, 'Force the configuration setting to be overwitten.', argument: :forbidden
|
|
111
111
|
|
|
112
|
-
option :t, :type,
|
|
113
|
-
option nil, :as,
|
|
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
114
|
|
|
115
115
|
run do |opts, args, _cmd|
|
|
116
116
|
exit PDK::CLI::Set::Config.run(opts, args)
|
data/lib/pdk/cli/set.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module PDK::CLI
|
|
2
2
|
@set_cmd = @base_cmd.define_command do
|
|
3
3
|
name 'set'
|
|
4
|
-
usage
|
|
5
|
-
summary
|
|
4
|
+
usage 'set [subcommand] [options]'
|
|
5
|
+
summary 'Set or update information about the PDK or current project.'
|
|
6
6
|
default_subcommand 'help'
|
|
7
7
|
|
|
8
8
|
run do |_opts, args, _cmd|
|
data/lib/pdk/cli/test/unit.rb
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
module PDK::CLI
|
|
2
2
|
@test_unit_cmd = @test_cmd.define_command do
|
|
3
3
|
name 'unit'
|
|
4
|
-
usage
|
|
5
|
-
summary
|
|
4
|
+
usage 'unit [options]'
|
|
5
|
+
summary 'Run unit tests.'
|
|
6
6
|
|
|
7
7
|
PDK::CLI.puppet_version_options(self)
|
|
8
8
|
PDK::CLI.puppet_dev_option(self)
|
|
9
|
-
flag nil, :list,
|
|
10
|
-
flag nil, :parallel,
|
|
11
|
-
flag :v, :verbose,
|
|
12
|
-
flag :c, 'clean-fixtures',
|
|
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
13
|
|
|
14
|
-
option nil, :tests,
|
|
14
|
+
option nil, :tests, 'Specify a comma-separated list of unit test files to run.', argument: :required, default: '' do |values|
|
|
15
15
|
require 'pdk/cli/util/option_validator'
|
|
16
16
|
PDK::CLI::Util::OptionValidator.comma_separated_list?(values)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# TODO
|
|
20
|
-
# option nil, :runner_options,
|
|
20
|
+
# option nil, :runner_options, "options to pass through to the actual test-runner", argument: :required
|
|
21
21
|
|
|
22
22
|
run do |opts, _args, _cmd|
|
|
23
23
|
require 'pdk/tests/unit'
|
|
@@ -27,7 +27,7 @@ module PDK::CLI
|
|
|
27
27
|
PDK::CLI::Util.validate_puppet_version_opts(opts)
|
|
28
28
|
|
|
29
29
|
PDK::CLI::Util.ensure_in_module!(
|
|
30
|
-
message:
|
|
30
|
+
message: 'Unit tests can only be run from inside a valid module directory.',
|
|
31
31
|
log_level: :info,
|
|
32
32
|
)
|
|
33
33
|
|
|
@@ -49,18 +49,18 @@ module PDK::CLI
|
|
|
49
49
|
examples = PDK::Test::Unit.list(opts)
|
|
50
50
|
|
|
51
51
|
if examples.empty?
|
|
52
|
-
puts
|
|
52
|
+
puts 'No unit test files with examples were found.'
|
|
53
53
|
else
|
|
54
|
-
puts
|
|
54
|
+
puts 'Unit Test Files:'
|
|
55
55
|
files = examples.map { |example| example[:file_path] }
|
|
56
56
|
files.uniq.each do |file|
|
|
57
|
-
puts
|
|
57
|
+
puts file
|
|
58
58
|
|
|
59
59
|
next unless opts[:verbose]
|
|
60
60
|
|
|
61
61
|
file_examples = examples.select { |example| example[:file_path] == file }
|
|
62
62
|
file_examples.each do |file_example|
|
|
63
|
-
puts
|
|
63
|
+
puts "\t%{id}\t%{description}" % { id: file_example[:id], description: file_example[:full_description] }
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
end
|
data/lib/pdk/cli/test.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module PDK::CLI
|
|
2
2
|
@test_cmd = @base_cmd.define_command do
|
|
3
3
|
name 'test'
|
|
4
|
-
usage
|
|
5
|
-
summary
|
|
4
|
+
usage 'test [subcommand] [options]'
|
|
5
|
+
summary 'Run tests.'
|
|
6
6
|
default_subcommand 'help'
|
|
7
7
|
end
|
|
8
8
|
@test_cmd.add_command Cri::Command.new_basic_help
|
data/lib/pdk/cli/update.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module PDK::CLI
|
|
2
2
|
@update_cmd = @base_cmd.define_command do
|
|
3
3
|
name 'update'
|
|
4
|
-
usage
|
|
5
|
-
summary
|
|
4
|
+
usage 'update [options]'
|
|
5
|
+
summary 'Update a module that has been created by or converted for use by PDK.'
|
|
6
6
|
|
|
7
|
-
flag nil, :noop,
|
|
8
|
-
flag nil, :force,
|
|
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
9
|
|
|
10
10
|
PDK::CLI.template_ref_option(self)
|
|
11
11
|
|
|
@@ -14,31 +14,23 @@ module PDK::CLI
|
|
|
14
14
|
PDK.context.to_debug_log
|
|
15
15
|
|
|
16
16
|
unless PDK.context.is_a?(PDK::Context::Module)
|
|
17
|
-
raise PDK::CLI::ExitWithError,
|
|
17
|
+
raise PDK::CLI::ExitWithError, '`pdk update` can only be run from inside a valid module directory.'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
raise PDK::CLI::ExitWithError,
|
|
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
21
|
|
|
22
22
|
if opts[:noop] && opts[:force]
|
|
23
|
-
raise PDK::CLI::ExitWithError,
|
|
23
|
+
raise PDK::CLI::ExitWithError, 'You can not specify --noop and --force when updating a module'
|
|
24
24
|
end
|
|
25
25
|
|
|
26
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
|
-
}
|
|
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!"
|
|
35
28
|
|
|
36
29
|
unless opts[:force]
|
|
37
|
-
raise PDK::CLI::ExitWithError,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)
|
|
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.'
|
|
42
34
|
end
|
|
43
35
|
end
|
|
44
36
|
|
|
@@ -47,15 +39,13 @@ module PDK::CLI
|
|
|
47
39
|
updater = PDK::Module::Update.new(PDK.context.root_path, opts)
|
|
48
40
|
|
|
49
41
|
if updater.pinned_to_puppetlabs_template_tag?
|
|
50
|
-
PDK.logger.info
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
new_version: PDK::TEMPLATE_REF,
|
|
58
|
-
}
|
|
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
|
+
}
|
|
59
49
|
end
|
|
60
50
|
|
|
61
51
|
updater.run
|
|
@@ -16,7 +16,7 @@ module PDK
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def run
|
|
19
|
-
@prompt.puts
|
|
19
|
+
@prompt.puts 'Did you mean \'%{command}\'?' % { command: pastel.bold(@command) }
|
|
20
20
|
@prompt.yes?('-->')
|
|
21
21
|
rescue PDK::CLI::Util::Interview::READER::InputInterrupt
|
|
22
22
|
nil
|
|
@@ -30,17 +30,17 @@ module PDK
|
|
|
30
30
|
num_questions = @questions.count
|
|
31
31
|
@questions.each do |question_name, question|
|
|
32
32
|
@name = question_name
|
|
33
|
-
@prompt.print pastel.bold(
|
|
33
|
+
@prompt.print pastel.bold('[Q %{current_number}/%{questions_total}]' % { current_number: i, questions_total: num_questions }) + ' '
|
|
34
34
|
@prompt.puts pastel.bold(question[:question])
|
|
35
35
|
@prompt.puts question[:help] if question.key?(:help)
|
|
36
36
|
|
|
37
37
|
case question[:type]
|
|
38
38
|
when :yes
|
|
39
|
-
yes?(
|
|
39
|
+
yes?('-->') do |q|
|
|
40
40
|
q.default(question[:default]) if question.key?(:default)
|
|
41
41
|
end
|
|
42
42
|
when :multi_select
|
|
43
|
-
multi_select(
|
|
43
|
+
multi_select('-->', per_page: question[:choices].count) do |q|
|
|
44
44
|
q.enum ')'
|
|
45
45
|
q.default(*question[:default]) if question.key?(:default)
|
|
46
46
|
|
|
@@ -49,7 +49,7 @@ module PDK
|
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
else
|
|
52
|
-
ask(
|
|
52
|
+
ask('-->') do |q|
|
|
53
53
|
q.required(question.fetch(:required, false))
|
|
54
54
|
|
|
55
55
|
if question.key?(:validate_pattern)
|
|
@@ -5,7 +5,7 @@ module PDK
|
|
|
5
5
|
module Util
|
|
6
6
|
class OptionNormalizer
|
|
7
7
|
def self.comma_separated_list_to_array(list, _options = {})
|
|
8
|
-
raise
|
|
8
|
+
raise 'Error: expected comma separated list' unless OptionValidator.comma_separated_list?(list)
|
|
9
9
|
list.split(',').compact
|
|
10
10
|
end
|
|
11
11
|
|
|
@@ -31,7 +31,7 @@ module PDK
|
|
|
31
31
|
begin
|
|
32
32
|
OptionValidator.enum(format, PDK::Report.formats)
|
|
33
33
|
rescue ArgumentError
|
|
34
|
-
raise PDK::CLI::ExitWithError,
|
|
34
|
+
raise PDK::CLI::ExitWithError, "'%{name}' is not a valid report format (%{valid})" % {
|
|
35
35
|
name: format,
|
|
36
36
|
valid: PDK::Report.formats.join(', '),
|
|
37
37
|
}
|
|
@@ -18,7 +18,7 @@ module PDK
|
|
|
18
18
|
invalid_entries = vals.reject { |e| valid_entries.include?(e) }
|
|
19
19
|
|
|
20
20
|
unless invalid_entries.empty?
|
|
21
|
-
raise ArgumentError,
|
|
21
|
+
raise ArgumentError, 'Error: the following values are invalid: %{invalid_entries}' % { invalid_entries: invalid_entries }
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
val
|
data/lib/pdk/cli/util.rb
CHANGED
|
@@ -23,7 +23,7 @@ module PDK
|
|
|
23
23
|
return unless PDK::Util.module_root.nil?
|
|
24
24
|
return if opts[:check_module_layout] && PDK::Util.in_module_root?
|
|
25
25
|
|
|
26
|
-
message = opts.fetch(:message,
|
|
26
|
+
message = opts.fetch(:message, 'This command must be run from inside a valid module (no metadata.json found).')
|
|
27
27
|
raise PDK::CLI::ExitWithError.new(message, opts)
|
|
28
28
|
end
|
|
29
29
|
module_function :ensure_in_module!
|
|
@@ -49,7 +49,7 @@ module PDK
|
|
|
49
49
|
begin
|
|
50
50
|
response = prompt.yes?(question_text) do |q|
|
|
51
51
|
q.default opts[:default] unless opts[:default].nil?
|
|
52
|
-
q.validate(validator,
|
|
52
|
+
q.validate(validator, 'Answer "Y" to continue or "n" to cancel.')
|
|
53
53
|
end
|
|
54
54
|
rescue PDK::CLI::Util::Interview::READER::InputInterrupt
|
|
55
55
|
PDK.logger.info opts[:cancel_message] if opts[:cancel_message]
|
|
@@ -96,22 +96,22 @@ module PDK
|
|
|
96
96
|
|
|
97
97
|
# This means the module does not have a pdk-version tag in the metadata.json
|
|
98
98
|
# and will require a pdk convert.
|
|
99
|
-
raise PDK::CLI::ExitWithError,
|
|
99
|
+
raise PDK::CLI::ExitWithError, 'This module is not PDK compatible. Run `pdk convert` to make it compatible with your version of PDK.' if module_pdk_ver.nil?
|
|
100
100
|
|
|
101
101
|
# This checks that the version of pdk in the module's metadata is older
|
|
102
102
|
# than 1.3.1, which means the module will need to run pdk convert to the
|
|
103
103
|
# new templates.
|
|
104
104
|
if Gem::Version.new(module_pdk_ver) < Gem::Version.new('1.3.1')
|
|
105
|
-
PDK.logger.warn
|
|
105
|
+
PDK.logger.warn 'This module template is out of date. Run `pdk convert` to make it compatible with your version of PDK.'
|
|
106
106
|
# This checks if the version of the installed PDK is older than the
|
|
107
107
|
# version in the module's metadata, and advises the user to upgrade to
|
|
108
108
|
# their install of PDK.
|
|
109
109
|
elsif Gem::Version.new(PDK::VERSION) < Gem::Version.new(module_pdk_ver)
|
|
110
|
-
PDK.logger.warn
|
|
110
|
+
PDK.logger.warn 'This module is compatible with a newer version of PDK. Upgrade your version of PDK to ensure compatibility.'
|
|
111
111
|
# This checks if the version listed in the module's metadata is older
|
|
112
112
|
# than the installed PDK, and advises the user to run pdk update.
|
|
113
113
|
elsif Gem::Version.new(PDK::VERSION) > Gem::Version.new(module_pdk_ver)
|
|
114
|
-
PDK.logger.warn
|
|
114
|
+
PDK.logger.warn 'This module is compatible with an older version of PDK. Run `pdk update` to update it to your version of PDK.'
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
module_function :module_version_check
|
|
@@ -122,10 +122,9 @@ module PDK
|
|
|
122
122
|
deprecated_below = Gem::Version.new('5.0.0')
|
|
123
123
|
return unless version < deprecated_below
|
|
124
124
|
|
|
125
|
-
deprecated_msg =
|
|
125
|
+
deprecated_msg =
|
|
126
126
|
'Support for Puppet versions older than %{version} is ' \
|
|
127
|
-
'deprecated and will be removed in a future version of PDK.'
|
|
128
|
-
) % { version: deprecated_below.to_s }
|
|
127
|
+
'deprecated and will be removed in a future version of PDK.' % { version: deprecated_below.to_s }
|
|
129
128
|
PDK.logger.warn(deprecated_msg)
|
|
130
129
|
end
|
|
131
130
|
module_function :check_for_deprecated_puppet
|
|
@@ -163,7 +162,7 @@ module PDK
|
|
|
163
162
|
|
|
164
163
|
# Notify user of what Ruby version will be used.
|
|
165
164
|
unless logging_disabled
|
|
166
|
-
PDK.logger.info(
|
|
165
|
+
PDK.logger.info('Using Ruby %{version}' % {
|
|
167
166
|
version: puppet_env[:ruby_version],
|
|
168
167
|
})
|
|
169
168
|
end
|
|
@@ -177,7 +176,7 @@ module PDK
|
|
|
177
176
|
gemset.each do |gem, version|
|
|
178
177
|
next if version.nil?
|
|
179
178
|
|
|
180
|
-
PDK.logger.info(
|
|
179
|
+
PDK.logger.info('Using %{gem} %{version}' % {
|
|
181
180
|
gem: gem.to_s.capitalize,
|
|
182
181
|
version: version,
|
|
183
182
|
})
|
|
@@ -208,7 +207,7 @@ module PDK
|
|
|
208
207
|
[puppet_ver_specs, pe_ver_specs].each do |offending|
|
|
209
208
|
next if offending.empty?
|
|
210
209
|
|
|
211
|
-
raise PDK::CLI::ExitWithError,
|
|
210
|
+
raise PDK::CLI::ExitWithError, 'You cannot specify a %{first} and %{second} at the same time.' % {
|
|
212
211
|
first: pup_dev_spec,
|
|
213
212
|
second: offending.first,
|
|
214
213
|
}
|
|
@@ -220,7 +219,7 @@ module PDK
|
|
|
220
219
|
|
|
221
220
|
offending = [pup_ver_spec, pe_ver_specs[0]].sort
|
|
222
221
|
|
|
223
|
-
raise PDK::CLI::ExitWithError,
|
|
222
|
+
raise PDK::CLI::ExitWithError, 'You cannot specify a %{first} and %{second} at the same time.' % {
|
|
224
223
|
first: offending[0],
|
|
225
224
|
second: offending[1],
|
|
226
225
|
}
|
|
@@ -230,7 +229,7 @@ module PDK
|
|
|
230
229
|
warning_str = 'Puppet dev flag from command line: "--puppet-dev" '
|
|
231
230
|
warning_str += 'overrides value from environment: "PDK_PUPPET_DEV=true". You should not specify both.'
|
|
232
231
|
|
|
233
|
-
PDK.logger.warn(
|
|
232
|
+
PDK.logger.warn(warning_str % {
|
|
234
233
|
pup_ver_opt: opts[:'puppet-dev'],
|
|
235
234
|
pup_ver_env: PDK::Util::Env['PDK_PUPPET_DEV'],
|
|
236
235
|
})
|
|
@@ -238,7 +237,7 @@ module PDK
|
|
|
238
237
|
warning_str = 'Puppet version option from command line: "--puppet-version=%{pup_ver_opt}" '
|
|
239
238
|
warning_str += 'overrides value from environment: "PDK_PUPPET_VERSION=%{pup_ver_env}". You should not specify both.'
|
|
240
239
|
|
|
241
|
-
PDK.logger.warn(
|
|
240
|
+
PDK.logger.warn(warning_str % {
|
|
242
241
|
pup_ver_opt: opts[:'puppet-version'],
|
|
243
242
|
pup_ver_env: PDK::Util::Env['PDK_PUPPET_VERSION'],
|
|
244
243
|
})
|
|
@@ -246,9 +245,9 @@ module PDK
|
|
|
246
245
|
warning_str = 'Puppet Enterprise version option from command line: "--pe-version=%{pe_ver_opt}" '
|
|
247
246
|
warning_str += 'overrides value from environment: "PDK_PE_VERSION=%{pe_ver_env}". You should not specify both.'
|
|
248
247
|
|
|
249
|
-
PDK.logger.warn(
|
|
250
|
-
|
|
251
|
-
|
|
248
|
+
PDK.logger.warn(warning_str % {
|
|
249
|
+
pe_ver_opt: opts[:'pe-version'],
|
|
250
|
+
pe_ver_env: PDK::Util::Env['PDK_PE_VERSION'],
|
|
252
251
|
})
|
|
253
252
|
end
|
|
254
253
|
end
|
|
@@ -256,11 +255,11 @@ module PDK
|
|
|
256
255
|
|
|
257
256
|
def validate_template_opts(opts)
|
|
258
257
|
if opts[:'template-ref'] && opts[:'template-url'].nil?
|
|
259
|
-
raise PDK::CLI::ExitWithError,
|
|
258
|
+
raise PDK::CLI::ExitWithError, '--template-ref requires --template-url to also be specified.'
|
|
260
259
|
end
|
|
261
260
|
|
|
262
261
|
return unless opts[:'template-url'] && opts[:'template-url'].include?('#')
|
|
263
|
-
raise PDK::CLI::ExitWithError,
|
|
262
|
+
raise PDK::CLI::ExitWithError, '--template-url may not be used to specify paths containing #\'s.'
|
|
264
263
|
end
|
|
265
264
|
module_function :validate_template_opts
|
|
266
265
|
|
data/lib/pdk/cli/validate.rb
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
module PDK::CLI
|
|
2
2
|
@validate_cmd = @base_cmd.define_command do
|
|
3
3
|
name 'validate'
|
|
4
|
-
usage
|
|
5
|
-
summary
|
|
6
|
-
description
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
'If not specified, validators are run against all applicable files in the module.',
|
|
13
|
-
)
|
|
4
|
+
usage 'validate [validators] [options] [targets]'
|
|
5
|
+
summary 'Run static analysis tests.'
|
|
6
|
+
description "Run metadata, YAML, Puppet, Ruby, or Tasks validation.\n\n" \
|
|
7
|
+
'[validators] is an optional comma-separated list of validators to use. ' \
|
|
8
|
+
'If not specified, all validators are used. ' \
|
|
9
|
+
"Note that when using PowerShell, the list of validators must be enclosed in single quotes.\n\n" \
|
|
10
|
+
'[targets] is an optional space-separated list of files or directories to be validated. ' \
|
|
11
|
+
'If not specified, validators are run against all applicable files in the module.'
|
|
14
12
|
|
|
15
13
|
PDK::CLI.puppet_version_options(self)
|
|
16
14
|
PDK::CLI.puppet_dev_option(self)
|
|
17
|
-
flag nil, :list,
|
|
18
|
-
flag :a, 'auto-correct',
|
|
19
|
-
flag nil, :parallel,
|
|
15
|
+
flag nil, :list, 'List all available validators.'
|
|
16
|
+
flag :a, 'auto-correct', 'Automatically correct problems where possible.'
|
|
17
|
+
flag nil, :parallel, 'Run validations in parallel.'
|
|
20
18
|
|
|
21
19
|
run do |opts, args, _cmd|
|
|
22
20
|
# Write the context information to the debug log
|
|
@@ -31,13 +29,13 @@ module PDK::CLI
|
|
|
31
29
|
|
|
32
30
|
if opts[:list]
|
|
33
31
|
PDK::CLI::Util.analytics_screen_view('validate', opts)
|
|
34
|
-
PDK.logger.info(
|
|
32
|
+
PDK.logger.info('Available validators: %{validator_names}' % { validator_names: PDK::Validate.validator_names.join(', ') })
|
|
35
33
|
exit 0
|
|
36
34
|
end
|
|
37
35
|
|
|
38
36
|
PDK::CLI::Util.validate_puppet_version_opts(opts)
|
|
39
37
|
unless PDK.feature_flag?('controlrepo') || PDK.context.is_a?(PDK::Context::Module)
|
|
40
|
-
raise PDK::CLI::ExitWithError.new(
|
|
38
|
+
raise PDK::CLI::ExitWithError.new('Code validation can only be run from inside a valid module directory', log_level: :error)
|
|
41
39
|
end
|
|
42
40
|
|
|
43
41
|
PDK::CLI::Util.module_version_check if PDK.context.is_a?(PDK::Context::Module)
|
|
@@ -58,7 +56,7 @@ module PDK::CLI
|
|
|
58
56
|
|
|
59
57
|
vals.reject { |v| PDK::Validate.validator_names.include?(v) }
|
|
60
58
|
.each do |v|
|
|
61
|
-
PDK.logger.warn(
|
|
59
|
+
PDK.logger.warn("Unknown validator '%{v}'. Available validators: %{validators}." % { v: v, validators: PDK::Validate.validator_names.join(', ') })
|
|
62
60
|
end
|
|
63
61
|
else
|
|
64
62
|
# This is a single item. Check if it's a known validator, or otherwise treat it as a target.
|
|
@@ -68,11 +66,11 @@ module PDK::CLI
|
|
|
68
66
|
else
|
|
69
67
|
targets = [args[0]]
|
|
70
68
|
# We now know that no validators were passed, so let the user know we're using all of them by default.
|
|
71
|
-
PDK.logger.info(
|
|
69
|
+
PDK.logger.info('Running all available validators...')
|
|
72
70
|
end
|
|
73
71
|
end
|
|
74
72
|
else
|
|
75
|
-
PDK.logger.info(
|
|
73
|
+
PDK.logger.info('Running all available validators...')
|
|
76
74
|
end
|
|
77
75
|
validators_to_run = PDK::Validate.validator_names if validators_to_run.nil?
|
|
78
76
|
|