pdk 1.9.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +744 -711
- data/README.md +23 -21
- data/lib/pdk/answer_file.rb +3 -112
- data/lib/pdk/bolt.rb +20 -0
- data/lib/pdk/cli/build.rb +51 -54
- data/lib/pdk/cli/bundle.rb +33 -29
- data/lib/pdk/cli/console.rb +148 -0
- data/lib/pdk/cli/convert.rb +46 -37
- data/lib/pdk/cli/env.rb +51 -0
- data/lib/pdk/cli/errors.rb +4 -3
- data/lib/pdk/cli/exec/command.rb +285 -0
- data/lib/pdk/cli/exec/interactive_command.rb +109 -0
- data/lib/pdk/cli/exec.rb +32 -201
- data/lib/pdk/cli/exec_group.rb +79 -43
- data/lib/pdk/cli/get/config.rb +26 -0
- data/lib/pdk/cli/get.rb +22 -0
- data/lib/pdk/cli/new/class.rb +20 -22
- data/lib/pdk/cli/new/defined_type.rb +21 -21
- data/lib/pdk/cli/new/fact.rb +27 -0
- data/lib/pdk/cli/new/function.rb +27 -0
- data/lib/pdk/cli/new/module.rb +40 -29
- data/lib/pdk/cli/new/provider.rb +18 -18
- data/lib/pdk/cli/new/task.rb +23 -22
- data/lib/pdk/cli/new/test.rb +52 -0
- data/lib/pdk/cli/new/transport.rb +27 -0
- data/lib/pdk/cli/new.rb +15 -9
- data/lib/pdk/cli/release/prep.rb +39 -0
- data/lib/pdk/cli/release/publish.rb +46 -0
- data/lib/pdk/cli/release.rb +185 -0
- data/lib/pdk/cli/remove/config.rb +83 -0
- data/lib/pdk/cli/remove.rb +22 -0
- data/lib/pdk/cli/set/config.rb +121 -0
- data/lib/pdk/cli/set.rb +22 -0
- data/lib/pdk/cli/test/unit.rb +71 -69
- data/lib/pdk/cli/test.rb +9 -8
- data/lib/pdk/cli/update.rb +38 -21
- data/lib/pdk/cli/util/command_redirector.rb +13 -3
- data/lib/pdk/cli/util/interview.rb +25 -9
- data/lib/pdk/cli/util/option_normalizer.rb +6 -6
- data/lib/pdk/cli/util/option_validator.rb +19 -9
- data/lib/pdk/cli/util/spinner.rb +13 -0
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
- data/lib/pdk/cli/util.rb +105 -48
- data/lib/pdk/cli/validate.rb +96 -111
- data/lib/pdk/cli.rb +134 -87
- data/lib/pdk/config/errors.rb +5 -0
- data/lib/pdk/config/ini_file.rb +184 -0
- data/lib/pdk/config/ini_file_setting.rb +35 -0
- data/lib/pdk/config/json.rb +35 -0
- data/lib/pdk/config/json_schema_namespace.rb +137 -0
- data/lib/pdk/config/json_schema_setting.rb +51 -0
- data/lib/pdk/config/json_with_schema.rb +47 -0
- data/lib/pdk/config/namespace.rb +362 -0
- data/lib/pdk/config/setting.rb +134 -0
- data/lib/pdk/config/task_schema.json +116 -0
- data/lib/pdk/config/validator.rb +31 -0
- data/lib/pdk/config/yaml.rb +41 -0
- data/lib/pdk/config/yaml_with_schema.rb +51 -0
- data/lib/pdk/config.rb +304 -0
- data/lib/pdk/context/control_repo.rb +61 -0
- data/lib/pdk/context/module.rb +28 -0
- data/lib/pdk/context/none.rb +22 -0
- data/lib/pdk/context.rb +98 -0
- data/lib/pdk/control_repo.rb +89 -0
- data/lib/pdk/generate/defined_type.rb +27 -33
- data/lib/pdk/generate/fact.rb +26 -0
- data/lib/pdk/generate/function.rb +49 -0
- data/lib/pdk/generate/module.rb +160 -153
- data/lib/pdk/generate/provider.rb +16 -69
- data/lib/pdk/generate/puppet_class.rb +27 -32
- data/lib/pdk/generate/puppet_object.rb +100 -159
- data/lib/pdk/generate/task.rb +34 -51
- data/lib/pdk/generate/transport.rb +34 -0
- data/lib/pdk/generate.rb +21 -8
- data/lib/pdk/logger.rb +24 -6
- data/lib/pdk/module/build.rb +125 -37
- data/lib/pdk/module/convert.rb +146 -65
- data/lib/pdk/module/metadata.rb +72 -71
- data/lib/pdk/module/release.rb +255 -0
- data/lib/pdk/module/update.rb +48 -37
- data/lib/pdk/module/update_manager.rb +75 -39
- data/lib/pdk/module.rb +10 -2
- data/lib/pdk/monkey_patches.rb +268 -0
- data/lib/pdk/report/event.rb +36 -48
- data/lib/pdk/report.rb +35 -22
- data/lib/pdk/template/fetcher/git.rb +84 -0
- data/lib/pdk/template/fetcher/local.rb +29 -0
- data/lib/pdk/template/fetcher.rb +100 -0
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +108 -0
- data/lib/pdk/template/renderer/v1/renderer.rb +131 -0
- data/lib/pdk/template/renderer/v1/template_file.rb +100 -0
- data/lib/pdk/template/renderer/v1.rb +25 -0
- data/lib/pdk/template/renderer.rb +97 -0
- data/lib/pdk/template/template_dir.rb +67 -0
- data/lib/pdk/template.rb +52 -0
- data/lib/pdk/tests/unit.rb +101 -51
- data/lib/pdk/util/bundler.rb +44 -42
- data/lib/pdk/util/changelog_generator.rb +138 -0
- data/lib/pdk/util/env.rb +48 -0
- data/lib/pdk/util/filesystem.rb +139 -2
- data/lib/pdk/util/git.rb +108 -8
- data/lib/pdk/util/json_finder.rb +86 -0
- data/lib/pdk/util/puppet_strings.rb +125 -0
- data/lib/pdk/util/puppet_version.rb +71 -87
- data/lib/pdk/util/ruby_version.rb +49 -25
- data/lib/pdk/util/template_uri.rb +283 -0
- data/lib/pdk/util/vendored_file.rb +34 -42
- data/lib/pdk/util/version.rb +11 -10
- data/lib/pdk/util/windows/api_types.rb +74 -44
- data/lib/pdk/util/windows/file.rb +31 -27
- data/lib/pdk/util/windows/process.rb +74 -0
- data/lib/pdk/util/windows/string.rb +19 -12
- data/lib/pdk/util/windows.rb +2 -0
- data/lib/pdk/util.rb +111 -124
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
- data/lib/pdk/validate/external_command_validator.rb +213 -0
- data/lib/pdk/validate/internal_ruby_validator.rb +101 -0
- data/lib/pdk/validate/invokable_validator.rb +238 -0
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +84 -0
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +76 -0
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +131 -0
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
- data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +38 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +135 -0
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +22 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +79 -0
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +83 -0
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +45 -0
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
- data/lib/pdk/validate/validator.rb +120 -0
- data/lib/pdk/validate/validator_group.rb +107 -0
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +86 -0
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
- data/lib/pdk/validate.rb +86 -12
- data/lib/pdk/version.rb +2 -2
- data/lib/pdk.rb +60 -10
- metadata +138 -100
- data/lib/pdk/cli/module/build.rb +0 -14
- data/lib/pdk/cli/module/generate.rb +0 -45
- data/lib/pdk/cli/module.rb +0 -14
- data/lib/pdk/i18n.rb +0 -4
- data/lib/pdk/module/templatedir.rb +0 -321
- data/lib/pdk/template_file.rb +0 -95
- data/lib/pdk/validate/base_validator.rb +0 -215
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -86
- data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -109
- data/lib/pdk/validate/metadata_validator.rb +0 -30
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -67
- data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -112
- data/lib/pdk/validate/puppet_validator.rb +0 -30
- data/lib/pdk/validate/ruby/rubocop.rb +0 -77
- data/lib/pdk/validate/ruby_validator.rb +0 -29
- data/lib/pdk/validate/tasks/metadata_lint.rb +0 -126
- data/lib/pdk/validate/tasks/name.rb +0 -88
- data/lib/pdk/validate/tasks_validator.rb +0 -33
- data/lib/pdk/validate/yaml/syntax.rb +0 -109
- data/lib/pdk/validate/yaml_validator.rb +0 -31
- data/locales/config.yaml +0 -21
- data/locales/pdk.pot +0 -1291
@@ -0,0 +1,22 @@
|
|
1
|
+
module PDK
|
2
|
+
module CLI
|
3
|
+
@remove_cmd = @base_cmd.define_command do
|
4
|
+
name 'remove'
|
5
|
+
usage 'remove [subcommand] [options]'
|
6
|
+
summary 'Remove or delete information about the PDK or current project.'
|
7
|
+
default_subcommand 'help'
|
8
|
+
|
9
|
+
run do |_opts, args, _cmd|
|
10
|
+
if args == ['help']
|
11
|
+
PDK::CLI.run(['remove', '--help'])
|
12
|
+
exit 0
|
13
|
+
end
|
14
|
+
|
15
|
+
PDK::CLI.run(['remove', 'help']) if args.empty?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@remove_cmd.add_command Cri::Command.new_basic_help
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'pdk/cli/remove/config'
|
@@ -0,0 +1,121 @@
|
|
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(', ')
|
10
|
+
end
|
11
|
+
# :nocov:
|
12
|
+
|
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
|
18
|
+
|
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)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.convert_to_array(value)
|
43
|
+
return [] if value.nil?
|
44
|
+
|
45
|
+
value.is_a?(Array) ? value : [value]
|
46
|
+
end
|
47
|
+
private_class_method :convert_to_array
|
48
|
+
|
49
|
+
def self.convert_to_boolean(value)
|
50
|
+
string_val = value.to_s.strip.downcase
|
51
|
+
|
52
|
+
return true if ['yes', 'true', '-1', '1'].include?(string_val)
|
53
|
+
return false if ['no', 'false', '0'].include?(string_val)
|
54
|
+
|
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
|
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
|
69
|
+
|
70
|
+
opts[:type] = opts[:as] if opts[:type].nil? && !opts[:as].nil?
|
71
|
+
force = opts[:force] || false
|
72
|
+
|
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?
|
75
|
+
|
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?
|
78
|
+
|
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)
|
81
|
+
|
82
|
+
# If we're forcing the value, don't do any munging
|
83
|
+
# Check if the setting already exists
|
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))
|
86
|
+
return 0
|
87
|
+
end
|
88
|
+
|
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
|
98
|
+
|
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
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
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>'
|
110
|
+
|
111
|
+
option :f, :force, 'Force the configuration setting to be overwitten.', argument: :forbidden
|
112
|
+
|
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
|
115
|
+
|
116
|
+
run do |opts, args, _cmd|
|
117
|
+
exit PDK::CLI::Set::Config.run(opts, args)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/lib/pdk/cli/set.rb
ADDED
@@ -0,0 +1,22 @@
|
|
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'
|
8
|
+
|
9
|
+
run do |_opts, args, _cmd|
|
10
|
+
if args == ['help']
|
11
|
+
PDK::CLI.run(['set', '--help'])
|
12
|
+
exit 0
|
13
|
+
end
|
14
|
+
|
15
|
+
PDK::CLI.run(['set', 'help']) if args.empty?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@set_cmd.add_command Cri::Command.new_basic_help
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'pdk/cli/set/config'
|
data/lib/pdk/cli/test/unit.rb
CHANGED
@@ -1,87 +1,89 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
# TODO
|
22
|
-
# option nil, :runner_options, _("options to pass through to the actual test-runner"), argument: :required
|
23
|
-
|
24
|
-
run do |opts, _args, _cmd|
|
25
|
-
require 'pdk/tests/unit'
|
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
|
26
19
|
|
27
|
-
|
20
|
+
# TODO
|
21
|
+
# option nil, :runner_options, "options to pass through to the actual test-runner", argument: :required
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
run do |opts, _args, _cmd|
|
24
|
+
require 'pdk/tests/unit'
|
25
|
+
require 'pdk/report'
|
26
|
+
require 'pdk/util/bundler'
|
33
27
|
|
34
|
-
|
28
|
+
PDK::CLI::Util.validate_puppet_version_opts(opts)
|
35
29
|
|
36
|
-
|
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
|
+
)
|
37
34
|
|
38
|
-
|
39
|
-
examples = PDK::Test::Unit.list
|
40
|
-
if examples.empty?
|
41
|
-
puts _('No unit test files with examples were found.')
|
42
|
-
else
|
43
|
-
puts _('Unit Test Files:')
|
44
|
-
files = examples.map { |example| example[:file_path] }
|
45
|
-
files.uniq.each do |file|
|
46
|
-
puts _(file)
|
35
|
+
PDK::CLI::Util.module_version_check
|
47
36
|
|
48
|
-
|
49
|
-
|
50
|
-
file_examples = examples.select { |example| example[:file_path] == file }
|
51
|
-
file_examples.each do |file_example|
|
52
|
-
puts _("\t%{id}\t%{description}" % { id: file_example[:id], description: file_example[:full_description] })
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
else
|
57
|
-
PDK.logger.info _('--verbose has no effect when not used with --list') if opts[:verbose]
|
58
|
-
|
59
|
-
report = PDK::Report.new
|
60
|
-
report_formats = if opts[:format]
|
61
|
-
PDK::CLI::Util::OptionNormalizer.report_formats(opts[:format])
|
62
|
-
else
|
63
|
-
[{
|
64
|
-
method: PDK::Report.default_format,
|
65
|
-
target: PDK::Report.default_target,
|
66
|
-
}]
|
67
|
-
end
|
68
|
-
|
69
|
-
# Ensure that the bundled gems are up to date and correct Ruby is activated before running tests.
|
37
|
+
# Ensure that the bundled gems are up to date and correct Ruby is activated before running or listing tests.
|
70
38
|
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
|
71
|
-
PDK::Util::PuppetVersion.fetch_puppet_dev if opts.key?(:'puppet-dev')
|
72
39
|
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
|
73
40
|
|
74
41
|
opts.merge!(puppet_env[:gemset])
|
75
42
|
|
76
43
|
PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
|
77
44
|
|
78
|
-
|
45
|
+
report = nil
|
79
46
|
|
80
|
-
|
81
|
-
|
82
|
-
|
47
|
+
if opts[:list]
|
48
|
+
examples = PDK::Test::Unit.list(opts)
|
49
|
+
|
50
|
+
if examples.empty?
|
51
|
+
puts 'No unit test files with examples were found.'
|
52
|
+
else
|
53
|
+
puts 'Unit Test Files:'
|
54
|
+
files = examples.map { |example| example[:file_path] }
|
55
|
+
files.uniq.each do |file|
|
56
|
+
puts file
|
57
|
+
|
58
|
+
next unless opts[:verbose]
|
83
59
|
|
84
|
-
|
60
|
+
file_examples = examples.select { |example| example[:file_path] == file }
|
61
|
+
file_examples.each do |file_example|
|
62
|
+
puts format("\t%{id}\t%{description}", id: file_example[:id], description: file_example[:full_description])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
else
|
67
|
+
report = PDK::Report.new
|
68
|
+
report_formats = if opts[:format]
|
69
|
+
opts[:interactive] = false
|
70
|
+
PDK::CLI::Util::OptionNormalizer.report_formats(opts[:format])
|
71
|
+
else
|
72
|
+
opts[:interactive] = true
|
73
|
+
[{
|
74
|
+
method: PDK::Report.default_format,
|
75
|
+
target: PDK::Report.default_target
|
76
|
+
}]
|
77
|
+
end
|
78
|
+
|
79
|
+
exit_code = PDK::Test::Unit.invoke(report, opts)
|
80
|
+
|
81
|
+
report_formats.each do |format|
|
82
|
+
report.send(format[:method], format[:target])
|
83
|
+
end
|
84
|
+
|
85
|
+
exit exit_code
|
86
|
+
end
|
85
87
|
end
|
86
88
|
end
|
87
89
|
end
|
data/lib/pdk/cli/test.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
8
10
|
end
|
9
|
-
@test_cmd.add_command Cri::Command.new_basic_help
|
10
11
|
end
|
11
12
|
|
12
13
|
require 'pdk/cli/test/unit'
|
data/lib/pdk/cli/update.rb
CHANGED
@@ -1,32 +1,49 @@
|
|
1
|
-
|
2
|
-
|
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.'
|
3
7
|
|
4
|
-
module
|
5
|
-
|
6
|
-
name 'update'
|
7
|
-
usage _('update [options]')
|
8
|
-
summary _('Update a module that has been created by or converted for use by PDK.')
|
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
|
-
flag nil, :force, _('Update the module automatically, with no prompts.')
|
11
|
+
PDK::CLI.template_ref_option(self)
|
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
|
-
|
18
|
-
|
19
|
-
)
|
17
|
+
unless PDK.context.is_a?(PDK::Context::Module) || PDK.context.is_a?(PDK::Context::ControlRepo)
|
18
|
+
raise PDK::CLI::ExitWithError, '`pdk update` can only be run from inside a valid module directory.'
|
19
|
+
end
|
20
20
|
|
21
|
-
|
21
|
+
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?
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
raise PDK::CLI::ExitWithError, 'You can not specify --noop and --force when updating a module' if opts[:noop] && opts[:force]
|
24
|
+
|
25
|
+
if Gem::Version.new(PDK::VERSION) < Gem::Version.new(PDK::Util.module_pdk_version)
|
26
|
+
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!"
|
27
|
+
|
28
|
+
unless opts[:force]
|
29
|
+
raise PDK::CLI::ExitWithError,
|
30
|
+
'Please update your PDK installation and try again. ' \
|
31
|
+
'You may also use the --force flag to override this and ' \
|
32
|
+
'continue at your own risk.'
|
33
|
+
end
|
34
|
+
end
|
26
35
|
|
27
|
-
|
36
|
+
updater = PDK::Module::Update.new(PDK.context.root_path, opts)
|
28
37
|
|
29
|
-
|
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
|
44
|
+
|
45
|
+
updater.run
|
46
|
+
end
|
30
47
|
end
|
31
48
|
end
|
32
49
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'pdk'
|
2
|
+
require 'tty/prompt'
|
2
3
|
|
3
4
|
module PDK
|
4
5
|
module CLI
|
@@ -6,6 +7,15 @@ module PDK
|
|
6
7
|
class CommandRedirector < TTY::Prompt::AnswersCollector
|
7
8
|
attr_accessor :command
|
8
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
|
+
|
9
19
|
def pastel
|
10
20
|
@pastel ||= Pastel.new
|
11
21
|
end
|
@@ -15,9 +25,9 @@ module PDK
|
|
15
25
|
end
|
16
26
|
|
17
27
|
def run
|
18
|
-
@prompt.puts
|
28
|
+
@prompt.puts "Did you mean '#{pastel.bold(@command)}'?"
|
19
29
|
@prompt.yes?('-->')
|
20
|
-
rescue
|
30
|
+
rescue PDK::CLI::Util::Interview::READER::InputInterrupt
|
21
31
|
nil
|
22
32
|
end
|
23
33
|
end
|
@@ -1,9 +1,21 @@
|
|
1
|
-
require 'tty
|
1
|
+
require 'tty/prompt'
|
2
|
+
require 'pdk'
|
2
3
|
|
3
4
|
module PDK
|
4
5
|
module CLI
|
5
6
|
module Util
|
6
7
|
class Interview < TTY::Prompt::AnswersCollector
|
8
|
+
READER = defined?(TTY::Reader) ? TTY::Reader : TTY::Prompt::Reader
|
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
|
+
|
7
19
|
def pastel
|
8
20
|
@pastel ||= Pastel.new
|
9
21
|
end
|
@@ -27,11 +39,17 @@ module PDK
|
|
27
39
|
num_questions = @questions.count
|
28
40
|
@questions.each do |question_name, question|
|
29
41
|
@name = question_name
|
30
|
-
@prompt.print pastel.bold(
|
42
|
+
@prompt.print "#{pastel.bold(format('[Q %{current_number}/%{questions_total}]', current_number: i, questions_total: num_questions))} "
|
31
43
|
@prompt.puts pastel.bold(question[:question])
|
32
44
|
@prompt.puts question[:help] if question.key?(:help)
|
33
|
-
|
34
|
-
|
45
|
+
|
46
|
+
case question[:type]
|
47
|
+
when :yes
|
48
|
+
yes?('-->') do |q|
|
49
|
+
q.default(question[:default]) if question.key?(:default)
|
50
|
+
end
|
51
|
+
when :multi_select
|
52
|
+
multi_select('-->', per_page: question[:choices].count) do |q|
|
35
53
|
q.enum ')'
|
36
54
|
q.default(*question[:default]) if question.key?(:default)
|
37
55
|
|
@@ -40,12 +58,10 @@ module PDK
|
|
40
58
|
end
|
41
59
|
end
|
42
60
|
else
|
43
|
-
ask(
|
61
|
+
ask('-->') do |q|
|
44
62
|
q.required(question.fetch(:required, false))
|
45
63
|
|
46
|
-
if question.key?(:validate_pattern)
|
47
|
-
q.validate(question[:validate_pattern], question[:validate_message])
|
48
|
-
end
|
64
|
+
q.validate(question[:validate_pattern], question[:validate_message]) if question.key?(:validate_pattern)
|
49
65
|
|
50
66
|
q.default(question[:default]) if question.key?(:default)
|
51
67
|
end
|
@@ -54,7 +70,7 @@ module PDK
|
|
54
70
|
@prompt.puts ''
|
55
71
|
end
|
56
72
|
@answers
|
57
|
-
rescue
|
73
|
+
rescue READER::InputInterrupt
|
58
74
|
nil
|
59
75
|
end
|
60
76
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'pdk'
|
2
|
+
|
1
3
|
module PDK
|
2
4
|
module CLI
|
3
5
|
module Util
|
4
6
|
class OptionNormalizer
|
5
7
|
def self.comma_separated_list_to_array(list, _options = {})
|
6
|
-
raise
|
8
|
+
raise 'Error: expected comma separated list' unless OptionValidator.comma_separated_list?(list)
|
9
|
+
|
7
10
|
list.split(',').compact
|
8
11
|
end
|
9
12
|
|
@@ -29,10 +32,7 @@ module PDK
|
|
29
32
|
begin
|
30
33
|
OptionValidator.enum(format, PDK::Report.formats)
|
31
34
|
rescue ArgumentError
|
32
|
-
raise PDK::CLI::ExitWithError,
|
33
|
-
name: format,
|
34
|
-
valid: PDK::Report.formats.join(', '),
|
35
|
-
}
|
35
|
+
raise PDK::CLI::ExitWithError, format("'%{name}' is not a valid report format (%{valid})", name: format, valid: PDK::Report.formats.join(', '))
|
36
36
|
end
|
37
37
|
|
38
38
|
case target
|
@@ -44,7 +44,7 @@ module PDK
|
|
44
44
|
target = PDK::Report.default_target
|
45
45
|
end
|
46
46
|
|
47
|
-
{ method: "write_#{format}"
|
47
|
+
{ method: :"write_#{format}", target: target }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -1,18 +1,23 @@
|
|
1
|
+
require 'pdk'
|
2
|
+
|
1
3
|
module PDK
|
2
4
|
module CLI
|
3
5
|
module Util
|
4
6
|
class OptionValidator
|
5
7
|
def self.comma_separated_list?(list, _options = {})
|
6
|
-
|
8
|
+
/^[\w-]+(?:,[\w-]+)+$/.match?(list)
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Boolean] true if the fact name is valid
|
12
|
+
def self.valid_fact_name?(name)
|
13
|
+
name.length > 1
|
7
14
|
end
|
8
15
|
|
9
16
|
def self.enum(val, valid_entries, _options = {})
|
10
17
|
vals = val.is_a?(Array) ? val : [val]
|
11
18
|
invalid_entries = vals.reject { |e| valid_entries.include?(e) }
|
12
19
|
|
13
|
-
unless invalid_entries.empty?
|
14
|
-
raise ArgumentError, _('Error: the following values are invalid: %{invalid_entries}') % { invalid_entries: invalid_entries }
|
15
|
-
end
|
20
|
+
raise ArgumentError, format('Error: the following values are invalid: %{invalid_entries}', invalid_entries: invalid_entries) unless invalid_entries.empty?
|
16
21
|
|
17
22
|
val
|
18
23
|
end
|
@@ -20,7 +25,7 @@ module PDK
|
|
20
25
|
# Validate the module name against the regular expression in the
|
21
26
|
# documentation: https://docs.puppet.com/puppet/4.10/modules_fundamentals.html#allowed-module-names
|
22
27
|
def self.valid_module_name?(string)
|
23
|
-
!(string =~
|
28
|
+
!(string =~ /\A[a-z][a-z0-9_]*\Z/).nil?
|
24
29
|
end
|
25
30
|
singleton_class.send(:alias_method, :valid_task_name?, :valid_module_name?)
|
26
31
|
|
@@ -28,13 +33,18 @@ module PDK
|
|
28
33
|
# Let's assume that only strings similar to module names can actually be resolved by the puppet language.
|
29
34
|
singleton_class.send(:alias_method, :valid_provider_name?, :valid_module_name?)
|
30
35
|
|
36
|
+
# The name has to be a ruby symbol.
|
37
|
+
# While overly strict, let's apply the provider and module name rules for consistency.
|
38
|
+
singleton_class.send(:alias_method, :valid_transport_name?, :valid_provider_name?)
|
39
|
+
|
31
40
|
# Validate a Puppet namespace against the regular expression in the
|
32
41
|
# documentation: https://docs.puppet.com/puppet/4.10/lang_reserved.html#classes-and-defined-resource-types
|
33
42
|
def self.valid_namespace?(string)
|
34
43
|
return false if (string || '').split('::').last == 'init'
|
35
44
|
|
36
|
-
!(string =~
|
45
|
+
!(string =~ /\A([a-z][a-z0-9_]*)(::[a-z][a-z0-9_]*)*\Z/).nil?
|
37
46
|
end
|
47
|
+
singleton_class.send(:alias_method, :valid_function_name?, :valid_namespace?)
|
38
48
|
|
39
49
|
singleton_class.send(:alias_method, :valid_class_name?, :valid_namespace?)
|
40
50
|
singleton_class.send(:alias_method, :valid_defined_type_name?, :valid_namespace?)
|
@@ -44,11 +54,11 @@ module PDK
|
|
44
54
|
# The parameter should also not be a reserved word or overload
|
45
55
|
# a metaparameter.
|
46
56
|
def self.valid_param_name?(string)
|
47
|
-
reserved_words =
|
48
|
-
metaparams =
|
57
|
+
reserved_words = ['trusted', 'facts', 'server_facts', 'title', 'name'].freeze
|
58
|
+
metaparams = ['alias', 'audit', 'before', 'loglevel', 'noop', 'notify', 'require', 'schedule', 'stage', 'subscribe', 'tag'].freeze
|
49
59
|
return false if reserved_words.include?(string) || metaparams.include?(string)
|
50
60
|
|
51
|
-
!(string =~
|
61
|
+
!(string =~ /\A[a-z][a-zA-Z0-9_]*\Z/).nil?
|
52
62
|
end
|
53
63
|
end
|
54
64
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'tty-spinner'
|
2
|
+
|
3
|
+
# Replace the built-in tty check in tty-spinner with our own implementation
|
4
|
+
# that allows us to mock the behaviour during acceptance tests.
|
5
|
+
module TTY
|
6
|
+
class Spinner
|
7
|
+
def tty?
|
8
|
+
require 'pdk/cli/util'
|
9
|
+
|
10
|
+
PDK::CLI::Util.interactive?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|