pdk 1.17.0 → 2.1.1
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 +148 -11
- data/README.md +1 -1
- data/lib/pdk.rb +1 -1
- data/lib/pdk/cli.rb +7 -1
- data/lib/pdk/cli/convert.rb +7 -9
- data/lib/pdk/cli/env.rb +52 -0
- data/lib/pdk/cli/exec/command.rb +11 -1
- data/lib/pdk/cli/new.rb +2 -0
- data/lib/pdk/cli/new/class.rb +2 -1
- data/lib/pdk/cli/new/defined_type.rb +2 -1
- data/lib/pdk/cli/new/fact.rb +29 -0
- data/lib/pdk/cli/new/function.rb +29 -0
- data/lib/pdk/cli/new/provider.rb +2 -1
- data/lib/pdk/cli/new/task.rb +2 -1
- data/lib/pdk/cli/new/test.rb +2 -1
- data/lib/pdk/cli/new/transport.rb +2 -1
- data/lib/pdk/cli/release.rb +1 -1
- data/lib/pdk/cli/release/publish.rb +11 -1
- data/lib/pdk/cli/remove.rb +20 -0
- data/lib/pdk/cli/remove/config.rb +80 -0
- data/lib/pdk/cli/set.rb +20 -0
- data/lib/pdk/cli/set/config.rb +119 -0
- data/lib/pdk/cli/update.rb +6 -8
- data/lib/pdk/cli/util.rb +1 -0
- data/lib/pdk/cli/util/option_validator.rb +6 -0
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
- data/lib/pdk/config.rb +96 -13
- data/lib/pdk/context.rb +8 -5
- data/lib/pdk/generate/defined_type.rb +25 -32
- data/lib/pdk/generate/fact.rb +25 -0
- data/lib/pdk/generate/function.rb +48 -0
- data/lib/pdk/generate/module.rb +11 -10
- data/lib/pdk/generate/provider.rb +15 -64
- data/lib/pdk/generate/puppet_class.rb +25 -31
- data/lib/pdk/generate/puppet_object.rb +83 -187
- data/lib/pdk/generate/task.rb +28 -46
- data/lib/pdk/generate/transport.rb +20 -74
- data/lib/pdk/module.rb +1 -1
- data/lib/pdk/module/convert.rb +43 -23
- data/lib/pdk/module/metadata.rb +6 -2
- data/lib/pdk/module/release.rb +8 -2
- data/lib/pdk/module/update.rb +7 -11
- data/lib/pdk/module/update_manager.rb +7 -0
- data/lib/pdk/report.rb +3 -3
- data/lib/pdk/report/event.rb +8 -2
- data/lib/pdk/template.rb +59 -0
- data/lib/pdk/template/fetcher.rb +98 -0
- data/lib/pdk/template/fetcher/git.rb +85 -0
- data/lib/pdk/template/fetcher/local.rb +28 -0
- data/lib/pdk/template/renderer.rb +96 -0
- data/lib/pdk/template/renderer/v1.rb +25 -0
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
- data/lib/pdk/template/template_dir.rb +67 -0
- data/lib/pdk/tests/unit.rb +8 -1
- data/lib/pdk/util.rb +4 -35
- data/lib/pdk/util/bundler.rb +1 -1
- data/lib/pdk/util/changelog_generator.rb +20 -3
- data/lib/pdk/util/json_finder.rb +85 -0
- data/lib/pdk/util/puppet_strings.rb +3 -3
- data/lib/pdk/util/puppet_version.rb +2 -2
- data/lib/pdk/util/ruby_version.rb +5 -1
- data/lib/pdk/util/template_uri.rb +9 -11
- data/lib/pdk/util/vendored_file.rb +1 -2
- data/lib/pdk/validate.rb +17 -10
- 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/invokable_validator.rb +8 -4
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +1 -1
- data/lib/pdk/validate/validator.rb +7 -0
- data/lib/pdk/validate/validator_group.rb +1 -0
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +2 -2
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +356 -228
- metadata +65 -28
- data/lib/pdk/module/template_dir.rb +0 -115
- data/lib/pdk/module/template_dir/base.rb +0 -268
- data/lib/pdk/module/template_dir/git.rb +0 -91
- data/lib/pdk/module/template_dir/local.rb +0 -21
- data/lib/pdk/template_file.rb +0 -96
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# pdk [](https://travis-ci.org/puppetlabs/pdk) [](https://ci.appveyor.com/project/puppetlabs/pdk) [](https://coveralls.io/github/puppetlabs/pdk?branch=main)
|
2
2
|
|
3
3
|
* [Installation](#installation)
|
4
4
|
* [Basic usage](#basic-usage)
|
data/lib/pdk.rb
CHANGED
@@ -11,7 +11,7 @@ module PDK
|
|
11
11
|
autoload :Logger, 'pdk/logger'
|
12
12
|
autoload :Module, 'pdk/module'
|
13
13
|
autoload :Report, 'pdk/report'
|
14
|
-
autoload :
|
14
|
+
autoload :Template, 'pdk/template'
|
15
15
|
autoload :TEMPLATE_REF, 'pdk/version'
|
16
16
|
autoload :Util, 'pdk/util'
|
17
17
|
autoload :Validate, 'pdk/validate'
|
data/lib/pdk/cli.rb
CHANGED
@@ -5,7 +5,10 @@ require 'pdk/cli/errors'
|
|
5
5
|
|
6
6
|
module TTY
|
7
7
|
autoload :Prompt, 'tty/prompt'
|
8
|
-
|
8
|
+
|
9
|
+
class Prompt
|
10
|
+
autoload :Test, 'tty/prompt/test'
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
14
|
class Cri::Command::CriExitException
|
@@ -156,14 +159,17 @@ module PDK::CLI
|
|
156
159
|
require 'pdk/cli/build'
|
157
160
|
require 'pdk/cli/config'
|
158
161
|
require 'pdk/cli/convert'
|
162
|
+
require 'pdk/cli/env'
|
159
163
|
require 'pdk/cli/get'
|
160
164
|
require 'pdk/cli/new'
|
165
|
+
require 'pdk/cli/set'
|
161
166
|
require 'pdk/cli/test'
|
162
167
|
require 'pdk/cli/update'
|
163
168
|
require 'pdk/cli/validate'
|
164
169
|
require 'pdk/cli/module'
|
165
170
|
require 'pdk/cli/console'
|
166
171
|
require 'pdk/cli/release'
|
172
|
+
require 'pdk/cli/remove'
|
167
173
|
|
168
174
|
@base_cmd.add_command Cri::Command.new_basic_help
|
169
175
|
end
|
data/lib/pdk/cli/convert.rb
CHANGED
@@ -14,14 +14,12 @@ module PDK::CLI
|
|
14
14
|
flag nil, :'default-template', _('Convert the module to use the default PDK template.')
|
15
15
|
|
16
16
|
run do |opts, _args, _cmd|
|
17
|
-
|
18
|
-
|
17
|
+
# Write the context information to the debug log
|
18
|
+
PDK.context.to_debug_log
|
19
19
|
|
20
|
-
PDK::
|
21
|
-
|
22
|
-
|
23
|
-
log_level: :info,
|
24
|
-
)
|
20
|
+
unless PDK.context.is_a?(PDK::Context::Module)
|
21
|
+
raise PDK::CLI::ExitWithError, _('`pdk convert` can only be run from inside a valid module directory.')
|
22
|
+
end
|
25
23
|
|
26
24
|
if opts[:noop] && opts[:force]
|
27
25
|
raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when converting a module')
|
@@ -31,7 +29,7 @@ module PDK::CLI
|
|
31
29
|
raise PDK::CLI::ExitWithError, _('You can not specify --template-url and --default-template.') if opts[:'template-url']
|
32
30
|
|
33
31
|
opts[:'template-url'] = PDK::Util::TemplateURI.default_template_addressable_uri.to_s
|
34
|
-
PDK.config.user
|
32
|
+
PDK.config.set(%w[user module_defaults template-url], nil)
|
35
33
|
end
|
36
34
|
|
37
35
|
PDK::CLI::Util.validate_template_opts(opts)
|
@@ -48,7 +46,7 @@ module PDK::CLI
|
|
48
46
|
opts[:'full-interview'] = false
|
49
47
|
end
|
50
48
|
|
51
|
-
PDK::Module::Convert.invoke(PDK
|
49
|
+
PDK::Module::Convert.invoke(PDK.context.root_path, opts)
|
52
50
|
end
|
53
51
|
end
|
54
52
|
end
|
data/lib/pdk/cli/env.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module PDK::CLI
|
2
|
+
@env_cmd = @base_cmd.define_command do
|
3
|
+
name 'env'
|
4
|
+
usage _('env')
|
5
|
+
summary _('(Experimental) Output environment variables for specific Puppet context')
|
6
|
+
description _(<<-EOF
|
7
|
+
[experimental] Aids in setting a CLI context for a specified version of Puppet by outputting export commands for necessary environment variables.
|
8
|
+
EOF
|
9
|
+
)
|
10
|
+
|
11
|
+
PDK::CLI.puppet_version_options(self)
|
12
|
+
PDK::CLI.puppet_dev_option(self)
|
13
|
+
|
14
|
+
run do |opts, _args, _cmd|
|
15
|
+
require 'pdk/util'
|
16
|
+
require 'pdk/util/ruby_version'
|
17
|
+
|
18
|
+
PDK::CLI::Util.validate_puppet_version_opts(opts)
|
19
|
+
|
20
|
+
PDK::CLI::Util.analytics_screen_view('env')
|
21
|
+
|
22
|
+
# Ensure that the correct Ruby is activated before running command.
|
23
|
+
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
|
24
|
+
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
|
25
|
+
|
26
|
+
resolved_env = {
|
27
|
+
'PDK_RESOLVED_PUPPET_VERSION' => puppet_env[:gemset][:puppet],
|
28
|
+
'PDK_RESOLVED_RUBY_VERSION' => puppet_env[:ruby_version],
|
29
|
+
}
|
30
|
+
|
31
|
+
resolved_env['GEM_HOME'] = PDK::Util::RubyVersion.gem_home
|
32
|
+
gem_path = PDK::Util::RubyVersion.gem_path
|
33
|
+
resolved_env['GEM_PATH'] = gem_path.empty? ? resolved_env['GEM_HOME'] : gem_path
|
34
|
+
|
35
|
+
# Make sure invocation of Ruby prefers our private installation.
|
36
|
+
package_binpath = PDK::Util.package_install? ? File.join(PDK::Util.pdk_package_basedir, 'bin') : nil
|
37
|
+
|
38
|
+
resolved_env['PATH'] = [
|
39
|
+
PDK::Util::RubyVersion.bin_path,
|
40
|
+
File.join(resolved_env['GEM_HOME'], 'bin'),
|
41
|
+
PDK::Util::RubyVersion.gem_paths_raw.map { |gem_path_raw| File.join(gem_path_raw, 'bin') },
|
42
|
+
package_binpath,
|
43
|
+
PDK::Util::Env['PATH'],
|
44
|
+
].compact.flatten.join(File::PATH_SEPARATOR)
|
45
|
+
|
46
|
+
resolved_env.each do |var, val|
|
47
|
+
puts "export #{var}=\"#{val}\""
|
48
|
+
end
|
49
|
+
exit 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/pdk/cli/exec/command.rb
CHANGED
@@ -27,7 +27,17 @@ module PDK
|
|
27
27
|
@argv = argv
|
28
28
|
|
29
29
|
@process = ChildProcess.build(*@argv)
|
30
|
-
|
30
|
+
# https://github.com/puppetlabs/pdk/issues/1083:
|
31
|
+
# When @process.leader is set, childprocess will set the CREATE_BREAKAWAY_FROM_JOB
|
32
|
+
# and JOB_OBJECT_LIMIT_BREAKAWAY_OK flags in the Win32 API calls. This will cause
|
33
|
+
# issues on systems > Windows 7 / Server 2008, if the JOB_OBJECT_LIMIT_BREAKAWAY_OK
|
34
|
+
# flag is set and the Task Scheduler is trying to kick off a job, it can sometimes
|
35
|
+
# result in ACCESS_DENIED being returned by the Win32 API, depending on the permission
|
36
|
+
# levels / user account this user.
|
37
|
+
# The resolution for pdk/issues/1083 is to ensure @process.leader is not set.
|
38
|
+
# This will potentially cause issues on older Windows systems, in which case we may
|
39
|
+
# need to revisit and conditionally set this param depending on what OS we're on
|
40
|
+
# @process.leader = true
|
31
41
|
|
32
42
|
@stdout = Tempfile.new('stdout', mode: TEMPFILE_MODE).tap { |io| io.sync = true }
|
33
43
|
@stderr = Tempfile.new('stderr', mode: TEMPFILE_MODE).tap { |io| io.sync = true }
|
data/lib/pdk/cli/new.rb
CHANGED
data/lib/pdk/cli/new/class.rb
CHANGED
@@ -25,7 +25,8 @@ module PDK::CLI
|
|
25
25
|
|
26
26
|
PDK::CLI::Util.analytics_screen_view('new_class', opts)
|
27
27
|
|
28
|
-
PDK::Generate::PuppetClass.new(PDK
|
28
|
+
updates = PDK::Generate::PuppetClass.new(PDK.context, class_name, opts).run
|
29
|
+
PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -25,7 +25,8 @@ module PDK::CLI
|
|
25
25
|
|
26
26
|
require 'pdk/generate/defined_type'
|
27
27
|
|
28
|
-
PDK::Generate::DefinedType.new(PDK
|
28
|
+
updates = PDK::Generate::DefinedType.new(PDK.context, defined_type_name, opts).run
|
29
|
+
PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PDK::CLI
|
2
|
+
@new_fact_cmd = @new_cmd.define_command do
|
3
|
+
name 'fact'
|
4
|
+
usage _('fact [options] <name>')
|
5
|
+
summary _('Create a new custom fact named <name> using given options')
|
6
|
+
|
7
|
+
run do |opts, args, _cmd|
|
8
|
+
PDK::CLI::Util.ensure_in_module!
|
9
|
+
|
10
|
+
fact_name = args[0]
|
11
|
+
|
12
|
+
if fact_name.nil? || fact_name.empty?
|
13
|
+
puts command.help
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
unless Util::OptionValidator.valid_fact_name?(fact_name)
|
18
|
+
raise PDK::CLI::ExitWithError, _("'%{name}' is not a valid fact name") % { name: fact_name }
|
19
|
+
end
|
20
|
+
|
21
|
+
PDK::CLI::Util.analytics_screen_view('new_fact', opts)
|
22
|
+
|
23
|
+
require 'pdk/generate/fact'
|
24
|
+
|
25
|
+
updates = PDK::Generate::Fact.new(PDK.context, fact_name, opts).run
|
26
|
+
PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PDK::CLI
|
2
|
+
@new_function_cmd = @new_cmd.define_command do
|
3
|
+
name 'function'
|
4
|
+
usage _('function [options] <name>')
|
5
|
+
summary _('Create a new function named <name> using given options')
|
6
|
+
option :t, :type, _('The function type, (native or v4)'), argument: :required, default: 'native'
|
7
|
+
|
8
|
+
run do |opts, args, _cmd|
|
9
|
+
PDK::CLI::Util.ensure_in_module!
|
10
|
+
|
11
|
+
function_name = args[0]
|
12
|
+
|
13
|
+
if function_name.nil? || function_name.empty?
|
14
|
+
puts command.help
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
|
18
|
+
unless Util::OptionValidator.valid_function_name?(function_name)
|
19
|
+
raise PDK::CLI::ExitWithError, _("'%{name}' is not a valid function name") % { name: function_name }
|
20
|
+
end
|
21
|
+
|
22
|
+
PDK::CLI::Util.analytics_screen_view('new_function', opts)
|
23
|
+
|
24
|
+
require 'pdk/generate/function'
|
25
|
+
updates = PDK::Generate::Function.new(PDK.context, function_name, opts).run
|
26
|
+
PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/pdk/cli/new/provider.rb
CHANGED
@@ -22,7 +22,8 @@ module PDK::CLI
|
|
22
22
|
|
23
23
|
require 'pdk/generate/provider'
|
24
24
|
|
25
|
-
PDK::Generate::Provider.new(PDK
|
25
|
+
updates = PDK::Generate::Provider.new(PDK.context, provider_name, opts).run
|
26
|
+
PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
data/lib/pdk/cli/new/task.rb
CHANGED
@@ -27,7 +27,8 @@ module PDK::CLI
|
|
27
27
|
|
28
28
|
PDK::CLI::Util.analytics_screen_view('new_task', opts)
|
29
29
|
|
30
|
-
PDK::Generate::Task.new(PDK
|
30
|
+
updates = PDK::Generate::Task.new(PDK.context, task_name, opts).run
|
31
|
+
PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
data/lib/pdk/cli/new/test.rb
CHANGED
@@ -40,7 +40,8 @@ module PDK::CLI
|
|
40
40
|
|
41
41
|
PDK::CLI::Util.analytics_screen_view('new_test', opts)
|
42
42
|
|
43
|
-
generator.new(PDK
|
43
|
+
updates = generator.new(PDK.context, obj['name'], opts.merge(spec_only: true)).run
|
44
|
+
PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
|
44
45
|
rescue PDK::Util::PuppetStrings::NoObjectError
|
45
46
|
raise PDK::CLI::ExitWithError, _('Unable to find anything called "%{object}" to generate unit tests for.') % { object: object_name }
|
46
47
|
rescue PDK::Util::PuppetStrings::NoGeneratorError => e
|
@@ -20,7 +20,8 @@ module PDK::CLI
|
|
20
20
|
|
21
21
|
require 'pdk/generate/transport'
|
22
22
|
|
23
|
-
PDK::Generate::Transport.new(PDK
|
23
|
+
updates = PDK::Generate::Transport.new(PDK.context, transport_name, opts).run
|
24
|
+
PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
data/lib/pdk/cli/release.rb
CHANGED
@@ -22,7 +22,7 @@ module PDK::CLI
|
|
22
22
|
option nil, :'forge-upload-url', _('Set forge upload url path.'),
|
23
23
|
argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases'
|
24
24
|
|
25
|
-
option nil, :'forge-token', _('Set Forge API token.'),
|
25
|
+
option nil, :'forge-token', _('Set Forge API token.'), default: nil
|
26
26
|
|
27
27
|
option nil, :version, _('Update the module to the specified version prior to release. When not specified, the new version will be computed from the Changelog where possible.'),
|
28
28
|
argument: :required
|
@@ -11,7 +11,7 @@ module PDK::CLI
|
|
11
11
|
option nil, :'forge-upload-url', _('Set forge upload url path.'),
|
12
12
|
argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases'
|
13
13
|
|
14
|
-
option nil, :'forge-token', _('Set Forge API token
|
14
|
+
option nil, :'forge-token', _('Set Forge API token (you may also set via environment variable PDK_FORGE_TOKEN)'), argument: :required
|
15
15
|
|
16
16
|
run do |opts, _args, cmd|
|
17
17
|
# Make sure build is being run in a valid module directory with a metadata.json
|
@@ -27,6 +27,16 @@ module PDK::CLI
|
|
27
27
|
opts[:'skip-build'] = true
|
28
28
|
opts[:'skip-versionset'] = true
|
29
29
|
opts[:force] = true unless PDK::CLI::Util.interactive?
|
30
|
+
opts[:'forge-token'] ||= PDK::Util::Env['PDK_FORGE_TOKEN']
|
31
|
+
|
32
|
+
if opts[:'forge-token'].nil? || opts[:'forge-token'].empty?
|
33
|
+
PDK.logger.error _(
|
34
|
+
'You must supply a Forge API token either via `--forge-token` option ' \
|
35
|
+
'or PDK_FORGE_TOKEN environment variable.',
|
36
|
+
)
|
37
|
+
|
38
|
+
exit 1
|
39
|
+
end
|
30
40
|
|
31
41
|
Release.prepare_publish_interview(TTY::Prompt.new(help_color: :cyan), opts) unless opts[:force]
|
32
42
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PDK::CLI
|
2
|
+
@remove_cmd = @base_cmd.define_command do
|
3
|
+
name 'remove'
|
4
|
+
usage _('remove [subcommand] [options]')
|
5
|
+
summary _('Remove or delete information about the PDK or current project.')
|
6
|
+
default_subcommand 'help'
|
7
|
+
|
8
|
+
run do |_opts, args, _cmd|
|
9
|
+
if args == ['help']
|
10
|
+
PDK::CLI.run(%w[remove --help])
|
11
|
+
exit 0
|
12
|
+
end
|
13
|
+
|
14
|
+
PDK::CLI.run(%w[remove help]) if args.empty?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@remove_cmd.add_command Cri::Command.new_basic_help
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'pdk/cli/remove/config'
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module PDK::CLI
|
2
|
+
module Remove
|
3
|
+
module Config
|
4
|
+
def self.run(opts, args)
|
5
|
+
item_name = (args.count > 0) ? args[0] : nil
|
6
|
+
item_value = (args.count > 1) ? args[1].strip : nil
|
7
|
+
item_value = nil if !item_value.nil? && item_value.empty?
|
8
|
+
|
9
|
+
force = opts[:force] || false
|
10
|
+
|
11
|
+
raise PDK::CLI::ExitWithError, _('Configuration name is required') if item_name.nil?
|
12
|
+
|
13
|
+
current_value = PDK.config.get(item_name)
|
14
|
+
raise PDK::CLI::ExitWithError, _("The configuration item '%{name}' can not be removed.") % { name: item_name } if current_value.is_a?(PDK::Config::Namespace)
|
15
|
+
if current_value.nil?
|
16
|
+
PDK.logger.info(_("Could not remove '%{name}' as it has not been set") % { name: item_name })
|
17
|
+
return 0
|
18
|
+
end
|
19
|
+
|
20
|
+
PDK.logger.info(_("Ignoring the item value '%{value}' as --force has been set") % { value: item_value }) if current_value.is_a?(Array) && !item_value.nil? && force
|
21
|
+
PDK.logger.info(_('Ignoring --force as the setting is not multi-valued')) if !current_value.is_a?(Array) && force
|
22
|
+
|
23
|
+
# FIXME: It'd be nice to shortcircuit deleting default values. This causes the configuration file
|
24
|
+
# to be saved, even though nothing actually changes
|
25
|
+
|
26
|
+
# For most value types, just changing the value to nil is enough, however Arrays are a special case.
|
27
|
+
# Unless they're forced, array removal with either remove a single entry (matched by .to_s) or clear the
|
28
|
+
# array. When forced, the array is completed removed just like a string or number.
|
29
|
+
if current_value.is_a?(Array) && !force
|
30
|
+
# If the user didn't set a value then set the array as empty, otherwise remove that one item
|
31
|
+
new_value = item_value.nil? ? [] : current_value.reject { |item| item.to_s == item_value }
|
32
|
+
if current_value.count == new_value.count
|
33
|
+
if item_value.nil?
|
34
|
+
PDK.logger.info(_("Could not remove '%{name}' as it is already empty") % { name: item_name })
|
35
|
+
else
|
36
|
+
PDK.logger.info(_("Could not remove '%{value}' from '%{name}' as it has not been set") % { value: item_value, name: item_name })
|
37
|
+
end
|
38
|
+
return 0
|
39
|
+
end
|
40
|
+
PDK.config.set(item_name, new_value, force: true)
|
41
|
+
else
|
42
|
+
# Set the value to nil for deleting.
|
43
|
+
PDK.config.set(item_name, nil, force: true)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Output the result to the user
|
47
|
+
new_value = PDK.config.get(item_name)
|
48
|
+
if current_value.is_a?(Array) && !force
|
49
|
+
# Arrays have a special output format. If item_value is nil then the user wanted to empty/clear
|
50
|
+
# the array otherwise they just wanted to remove a single entry.
|
51
|
+
if item_value.nil?
|
52
|
+
PDK.logger.info(_("Cleared '%{name}' which had a value of '%{from}'") % { name: item_name, from: current_value })
|
53
|
+
else
|
54
|
+
PDK.logger.info(_("Removed '%{value}' from '%{name}'") % { value: item_value, name: item_name })
|
55
|
+
end
|
56
|
+
elsif !new_value.nil?
|
57
|
+
PDK.logger.info(_("Could not remove '%{name}' as it using a default value of '%{to}'") % { name: item_name, to: new_value })
|
58
|
+
else
|
59
|
+
PDK.logger.info(_("Removed '%{name}' which had a value of '%{from}'") % { name: item_name, from: current_value })
|
60
|
+
end
|
61
|
+
|
62
|
+
# Same output as `get config`
|
63
|
+
$stdout.puts _('%{name}=%{value}') % { name: item_name, value: new_value }
|
64
|
+
0
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
@remove_config_cmd = @remove_cmd.define_command do
|
70
|
+
name 'config'
|
71
|
+
usage _('config [name] [value]')
|
72
|
+
summary _('Remove or delete the configuration for <name>')
|
73
|
+
|
74
|
+
option :f, :force, _('Force multi-value configuration settings to be removed instead of emptied.'), argument: :forbidden
|
75
|
+
|
76
|
+
run do |opts, args, _cmd|
|
77
|
+
exit PDK::CLI::Remove::Config.run(opts, args)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/pdk/cli/set.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module PDK::CLI
|
2
|
+
@set_cmd = @base_cmd.define_command do
|
3
|
+
name 'set'
|
4
|
+
usage _('set [subcommand] [options]')
|
5
|
+
summary _('Set or update information about the PDK or current project.')
|
6
|
+
default_subcommand 'help'
|
7
|
+
|
8
|
+
run do |_opts, args, _cmd|
|
9
|
+
if args == ['help']
|
10
|
+
PDK::CLI.run(%w[set --help])
|
11
|
+
exit 0
|
12
|
+
end
|
13
|
+
|
14
|
+
PDK::CLI.run(%w[set help]) if args.empty?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@set_cmd.add_command Cri::Command.new_basic_help
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'pdk/cli/set/config'
|