pdk 2.7.1 → 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 +25 -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/release.rb
CHANGED
@@ -5,183 +5,186 @@ require 'pdk/cli/util/interview'
|
|
5
5
|
require 'pdk/util/changelog_generator'
|
6
6
|
require 'pdk/module/build'
|
7
7
|
|
8
|
-
module PDK
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
module PDK
|
9
|
+
module CLI
|
10
|
+
@release_cmd = @base_cmd.define_command do
|
11
|
+
name 'release'
|
12
|
+
usage 'release [options]'
|
13
|
+
summary '(Experimental) Release a module to the Puppet Forge.'
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
flag nil, :force, 'Release the module automatically, with no prompts.'
|
16
|
+
flag nil, :'skip-validation', 'Skips the module validation check.'
|
17
|
+
flag nil, :'skip-changelog', 'Skips the automatic changelog generation.'
|
18
|
+
flag nil, :'skip-dependency', 'Skips the module dependency check.'
|
19
|
+
flag nil, :'skip-documentation', 'Skips the documentation update.'
|
20
|
+
flag nil, :'skip-build', 'Skips module build.'
|
21
|
+
flag nil, :'skip-publish', 'Skips publishing the module to the forge.'
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
option nil, :'forge-upload-url', 'Set forge upload url path.',
|
24
|
+
argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases'
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
option nil, :'forge-token', 'Set Forge API token.',
|
27
|
+
argument: :optional
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
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.',
|
30
|
+
argument: :required
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
option nil, :file, 'Path to the built module to push to the Forge. This option can only be used when --skip-build is also used. Defaults to pkg/<module version>.tar.gz',
|
33
|
+
argument: :required
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
run do |opts, _args, _cmd|
|
36
|
+
# Make sure build is being run in a valid module directory with a metadata.json
|
37
|
+
PDK::CLI::Util.ensure_in_module!(
|
38
|
+
message: '`pdk release` can only be run from inside a valid module with a metadata.json.',
|
39
|
+
log_level: :info
|
40
|
+
)
|
40
41
|
|
41
|
-
|
42
|
+
Release.prepare_interview(opts) unless opts[:force]
|
42
43
|
|
43
|
-
|
44
|
+
Release.send_analytics('release', opts)
|
44
45
|
|
45
|
-
|
46
|
+
release = PDK::Module::Release.new(nil, opts)
|
46
47
|
|
47
|
-
|
48
|
+
Release.module_compatibility_checks!(release, opts)
|
48
49
|
|
49
|
-
|
50
|
+
release.run
|
51
|
+
end
|
50
52
|
end
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
module Release
|
55
|
+
# Checks whether the module is compatible with PDK release process
|
56
|
+
# @param release PDK::Module::Release Object representing the release
|
57
|
+
# @param opts Options Hash from Cri
|
58
|
+
def self.module_compatibility_checks!(release, opts)
|
59
|
+
unless release.module_metadata.forge_ready?
|
60
|
+
if opts[:force]
|
61
|
+
PDK.logger.warn "This module is missing the following fields in the metadata.json: #{release.module_metadata.missing_fields.join(', ')}. " \
|
62
|
+
'These missing fields may affect the visibility of the module on the Forge.'
|
63
|
+
else
|
64
|
+
release.module_metadata.interview_for_forge!
|
65
|
+
release.write_module_metadata!
|
66
|
+
end
|
65
67
|
end
|
66
|
-
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
69
|
+
unless release.pdk_compatible? # rubocop:disable Style/GuardClause Nope!
|
70
|
+
if opts[:force]
|
71
|
+
PDK.logger.warn 'This module is not compatible with PDK, so PDK can not validate or test this build.'
|
72
|
+
else
|
73
|
+
PDK.logger.info 'This module is not compatible with PDK, so PDK can not validate or test this build. ' \
|
74
|
+
'Unvalidated modules may have errors when uploading to the Forge. ' \
|
75
|
+
'To make this module PDK compatible and use validate features, cancel the build and run `pdk convert`.'
|
76
|
+
unless PDK::CLI::Util.prompt_for_yes('Continue build without converting?')
|
77
|
+
PDK.logger.info 'Build cancelled; exiting.'
|
78
|
+
PDK::Util.exit_process(1)
|
79
|
+
end
|
78
80
|
end
|
79
81
|
end
|
80
82
|
end
|
81
|
-
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
# Send_analytics for the given command and Cri options
|
85
|
+
def self.send_analytics(command, opts)
|
86
|
+
# Don't pass tokens to analytics
|
87
|
+
PDK::CLI::Util.analytics_screen_view(command, opts.reject { |k, _| k == :'forge-token' })
|
88
|
+
end
|
88
89
|
|
89
|
-
|
90
|
-
|
90
|
+
def self.prepare_interview(opts)
|
91
|
+
questions = []
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
93
|
+
unless opts[:'skip-validation']
|
94
|
+
questions << {
|
95
|
+
name: 'validation',
|
96
|
+
question: 'Do you want to run the module validation ?',
|
97
|
+
type: :yes
|
98
|
+
}
|
99
|
+
end
|
100
|
+
unless opts[:'skip-changelog']
|
101
|
+
questions << {
|
102
|
+
name: 'changelog',
|
103
|
+
question: 'Do you want to run the automatic changelog generation ?',
|
104
|
+
type: :yes
|
105
|
+
}
|
106
|
+
end
|
107
|
+
unless opts[:version]
|
108
|
+
questions << {
|
109
|
+
name: 'setversion',
|
110
|
+
question: 'Do you want to set the module version ?',
|
111
|
+
type: :yes
|
112
|
+
}
|
113
|
+
end
|
114
|
+
unless opts[:'skip-dependency']
|
115
|
+
questions << {
|
116
|
+
name: 'dependency',
|
117
|
+
question: 'Do you want to run the dependency-checker on this module?',
|
118
|
+
type: :yes
|
119
|
+
}
|
120
|
+
end
|
121
|
+
unless opts[:'skip-documentation']
|
122
|
+
questions << {
|
123
|
+
name: 'documentation',
|
124
|
+
question: 'Do you want to update the documentation for this module?',
|
125
|
+
type: :yes
|
126
|
+
}
|
127
|
+
end
|
128
|
+
unless opts[:'skip-publish']
|
129
|
+
questions << {
|
130
|
+
name: 'publish',
|
131
|
+
question: 'Do you want to publish the module on the Puppet Forge?',
|
132
|
+
type: :yes
|
133
|
+
}
|
134
|
+
end
|
134
135
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
136
|
+
prompt = TTY::Prompt.new(help_color: :cyan)
|
137
|
+
interview = PDK::CLI::Util::Interview.new(prompt)
|
138
|
+
interview.add_questions(questions)
|
139
|
+
answers = interview.run
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
141
|
+
unless answers.nil?
|
142
|
+
opts[:'skip-validation'] = !answers['validation']
|
143
|
+
opts[:'skip-changelog'] = !answers['changelog']
|
144
|
+
opts[:'skip-dependency'] = !answers['dependency']
|
145
|
+
opts[:'skip-documentation'] = !answers['documentation']
|
146
|
+
opts[:'skip-publish'] = !answers['publish']
|
146
147
|
|
147
|
-
|
148
|
+
prepare_version_interview(prompt, opts) if answers['setversion']
|
148
149
|
|
149
|
-
|
150
|
+
prepare_publish_interview(prompt, opts) if answers['publish']
|
151
|
+
end
|
152
|
+
answers
|
150
153
|
end
|
151
|
-
answers
|
152
|
-
end
|
153
154
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
155
|
+
def self.prepare_version_interview(prompt, opts)
|
156
|
+
questions = [
|
157
|
+
{
|
158
|
+
name: 'version',
|
159
|
+
question: 'Please set the module version',
|
160
|
+
help: 'This value is the version that will be used in the changelog generator and building of the module.',
|
161
|
+
required: true,
|
162
|
+
validate_pattern: /(\*|\d+(\.\d+){0,2}(\.\*)?)$/i,
|
163
|
+
validate_message: 'The version format should be in the format x.y.z where x represents the major version, y the minor version and z the build number.'
|
164
|
+
}
|
165
|
+
]
|
166
|
+
interview = PDK::CLI::Util::Interview.new(prompt)
|
167
|
+
interview.add_questions(questions)
|
168
|
+
ver_answer = interview.run
|
169
|
+
opts[:version] = ver_answer['version']
|
170
|
+
end
|
170
171
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
172
|
+
def self.prepare_publish_interview(prompt, opts)
|
173
|
+
return if opts[:'forge-token']
|
174
|
+
|
175
|
+
questions = [
|
176
|
+
{
|
177
|
+
name: 'apikey',
|
178
|
+
question: 'Please set the api key(authorization token) to upload on the Puppet Forge',
|
179
|
+
help: 'This value is used for authentication on the Puppet Forge to upload your module tarball.',
|
180
|
+
required: true
|
181
|
+
}
|
182
|
+
]
|
183
|
+
interview = PDK::CLI::Util::Interview.new(prompt)
|
184
|
+
interview.add_questions(questions)
|
185
|
+
api_answer = interview.run
|
186
|
+
opts[:'forge-token'] = api_answer['apikey']
|
187
|
+
end
|
185
188
|
end
|
186
189
|
end
|
187
190
|
end
|
@@ -1,80 +1,83 @@
|
|
1
|
-
module PDK
|
2
|
-
module
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module PDK
|
2
|
+
module CLI
|
3
|
+
module Remove
|
4
|
+
module Config
|
5
|
+
def self.run(opts, args)
|
6
|
+
item_name = args.count.positive? ? args[0] : nil
|
7
|
+
item_value = args.count > 1 ? args[1].strip : nil
|
8
|
+
item_value = nil if !item_value.nil? && item_value.empty?
|
8
9
|
|
9
|
-
|
10
|
+
force = opts[:force] || false
|
10
11
|
|
11
|
-
|
12
|
+
raise PDK::CLI::ExitWithError, 'Configuration name is required' if item_name.nil?
|
12
13
|
|
13
|
-
|
14
|
-
|
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
|
14
|
+
current_value = PDK.config.get(item_name)
|
15
|
+
raise PDK::CLI::ExitWithError, format("The configuration item '%{name}' can not be removed.", name: item_name) if current_value.is_a?(PDK::Config::Namespace)
|
19
16
|
|
20
|
-
|
21
|
-
|
17
|
+
if current_value.nil?
|
18
|
+
PDK.logger.info(format("Could not remove '%{name}' as it has not been set", name: item_name))
|
19
|
+
return 0
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
PDK.logger.info(format("Ignoring the item value '%{value}' as --force has been set", value: item_value)) if current_value.is_a?(Array) && !item_value.nil? && force
|
23
|
+
PDK.logger.info('Ignoring --force as the setting is not multi-valued') if !current_value.is_a?(Array) && force
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
#
|
31
|
-
|
32
|
-
if current_value.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
25
|
+
# FIXME: It'd be nice to shortcircuit deleting default values. This causes the configuration file
|
26
|
+
# to be saved, even though nothing actually changes
|
27
|
+
|
28
|
+
# For most value types, just changing the value to nil is enough, however Arrays are a special case.
|
29
|
+
# Unless they're forced, array removal with either remove a single entry (matched by .to_s) or clear the
|
30
|
+
# array. When forced, the array is completed removed just like a string or number.
|
31
|
+
if current_value.is_a?(Array) && !force
|
32
|
+
# If the user didn't set a value then set the array as empty, otherwise remove that one item
|
33
|
+
new_value = item_value.nil? ? [] : current_value.reject { |item| item.to_s == item_value }
|
34
|
+
if current_value.count == new_value.count
|
35
|
+
if item_value.nil?
|
36
|
+
PDK.logger.info(format("Could not remove '%{name}' as it is already empty", name: item_name))
|
37
|
+
else
|
38
|
+
PDK.logger.info(format("Could not remove '%{value}' from '%{name}' as it has not been set", value: item_value, name: item_name))
|
39
|
+
end
|
40
|
+
return 0
|
37
41
|
end
|
38
|
-
|
42
|
+
PDK.config.set(item_name, new_value, force: true)
|
43
|
+
else
|
44
|
+
# Set the value to nil for deleting.
|
45
|
+
PDK.config.set(item_name, nil, force: true)
|
39
46
|
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
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
# Output the result to the user
|
49
|
+
new_value = PDK.config.get(item_name)
|
50
|
+
if current_value.is_a?(Array) && !force
|
51
|
+
# Arrays have a special output format. If item_value is nil then the user wanted to empty/clear
|
52
|
+
# the array otherwise they just wanted to remove a single entry.
|
53
|
+
if item_value.nil?
|
54
|
+
PDK.logger.info(format("Cleared '%{name}' which had a value of '%{from}'", name: item_name, from: current_value))
|
55
|
+
else
|
56
|
+
PDK.logger.info(format("Removed '%{value}' from '%{name}'", value: item_value, name: item_name))
|
57
|
+
end
|
58
|
+
elsif !new_value.nil?
|
59
|
+
PDK.logger.info(format("Could not remove '%{name}' as it using a default value of '%{to}'", name: item_name, to: new_value))
|
53
60
|
else
|
54
|
-
PDK.logger.info("Removed '%{
|
61
|
+
PDK.logger.info(format("Removed '%{name}' which had a value of '%{from}'", name: item_name, from: current_value))
|
55
62
|
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
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
# Same output as `get config`
|
65
|
+
$stdout.puts format('%{name}=%{value}', name: item_name, value: new_value)
|
66
|
+
0
|
67
|
+
end
|
65
68
|
end
|
66
69
|
end
|
67
|
-
end
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
@remove_config_cmd = @remove_cmd.define_command do
|
72
|
+
name 'config'
|
73
|
+
usage 'config [name] [value]'
|
74
|
+
summary 'Remove or delete the configuration for <name>'
|
73
75
|
|
74
|
-
|
76
|
+
option :f, :force, 'Force multi-value configuration settings to be removed instead of emptied.', argument: :forbidden
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
+
run do |opts, args, _cmd|
|
79
|
+
exit PDK::CLI::Remove::Config.run(opts, args)
|
80
|
+
end
|
78
81
|
end
|
79
82
|
end
|
80
83
|
end
|
data/lib/pdk/cli/remove.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
module PDK
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
run do |_opts, args, _cmd|
|
10
|
+
if args == ['help']
|
11
|
+
PDK::CLI.run(['remove', '--help'])
|
12
|
+
exit 0
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
PDK::CLI.run(['remove', 'help']) if args.empty?
|
16
|
+
end
|
15
17
|
end
|
18
|
+
@remove_cmd.add_command Cri::Command.new_basic_help
|
16
19
|
end
|
17
|
-
@remove_cmd.add_command Cri::Command.new_basic_help
|
18
20
|
end
|
19
21
|
|
20
22
|
require 'pdk/cli/remove/config'
|