pdk 2.7.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +2 -48
  4. data/lib/pdk/analytics/client/google_analytics.rb +22 -26
  5. data/lib/pdk/analytics/util.rb +0 -1
  6. data/lib/pdk/analytics.rb +1 -1
  7. data/lib/pdk/bolt.rb +1 -0
  8. data/lib/pdk/cli/build.rb +53 -56
  9. data/lib/pdk/cli/bundle.rb +34 -33
  10. data/lib/pdk/cli/console.rb +136 -134
  11. data/lib/pdk/cli/convert.rb +39 -41
  12. data/lib/pdk/cli/env.rb +49 -47
  13. data/lib/pdk/cli/errors.rb +1 -2
  14. data/lib/pdk/cli/exec/command.rb +23 -29
  15. data/lib/pdk/cli/exec/interactive_command.rb +7 -12
  16. data/lib/pdk/cli/exec.rb +4 -11
  17. data/lib/pdk/cli/exec_group.rb +3 -2
  18. data/lib/pdk/cli/get/config.rb +21 -19
  19. data/lib/pdk/cli/get.rb +15 -13
  20. data/lib/pdk/cli/new/class.rb +22 -22
  21. data/lib/pdk/cli/new/defined_type.rb +22 -22
  22. data/lib/pdk/cli/new/fact.rb +19 -19
  23. data/lib/pdk/cli/new/function.rb +20 -20
  24. data/lib/pdk/cli/new/module.rb +40 -38
  25. data/lib/pdk/cli/new/provider.rb +19 -19
  26. data/lib/pdk/cli/new/task.rb +23 -23
  27. data/lib/pdk/cli/new/test.rb +50 -48
  28. data/lib/pdk/cli/new/transport.rb +18 -18
  29. data/lib/pdk/cli/new.rb +11 -9
  30. data/lib/pdk/cli/release/prep.rb +27 -25
  31. data/lib/pdk/cli/release/publish.rb +39 -37
  32. data/lib/pdk/cli/release.rb +152 -149
  33. data/lib/pdk/cli/remove/config.rb +63 -60
  34. data/lib/pdk/cli/remove.rb +15 -13
  35. data/lib/pdk/cli/set/config.rb +91 -89
  36. data/lib/pdk/cli/set.rb +15 -13
  37. data/lib/pdk/cli/test/unit.rb +71 -69
  38. data/lib/pdk/cli/test.rb +9 -7
  39. data/lib/pdk/cli/update.rb +33 -38
  40. data/lib/pdk/cli/util/command_redirector.rb +10 -1
  41. data/lib/pdk/cli/util/interview.rb +11 -4
  42. data/lib/pdk/cli/util/option_normalizer.rb +2 -4
  43. data/lib/pdk/cli/util/option_validator.rb +7 -9
  44. data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
  45. data/lib/pdk/cli/util.rb +32 -48
  46. data/lib/pdk/cli/validate.rb +98 -96
  47. data/lib/pdk/cli.rb +124 -120
  48. data/lib/pdk/config/ini_file.rb +4 -3
  49. data/lib/pdk/config/ini_file_setting.rb +6 -10
  50. data/lib/pdk/config/json.rb +1 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +5 -10
  52. data/lib/pdk/config/json_schema_setting.rb +3 -5
  53. data/lib/pdk/config/json_with_schema.rb +2 -4
  54. data/lib/pdk/config/namespace.rb +19 -13
  55. data/lib/pdk/config/setting.rb +5 -6
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +4 -4
  58. data/lib/pdk/config/yaml.rb +3 -8
  59. data/lib/pdk/config/yaml_with_schema.rb +4 -12
  60. data/lib/pdk/config.rb +47 -51
  61. data/lib/pdk/context/control_repo.rb +3 -2
  62. data/lib/pdk/context/module.rb +2 -2
  63. data/lib/pdk/context/none.rb +2 -2
  64. data/lib/pdk/context.rb +4 -5
  65. data/lib/pdk/control_repo.rb +3 -4
  66. data/lib/pdk/generate/defined_type.rb +3 -3
  67. data/lib/pdk/generate/fact.rb +3 -2
  68. data/lib/pdk/generate/function.rb +5 -4
  69. data/lib/pdk/generate/module.rb +91 -106
  70. data/lib/pdk/generate/provider.rb +5 -4
  71. data/lib/pdk/generate/puppet_class.rb +3 -3
  72. data/lib/pdk/generate/puppet_object.rb +9 -12
  73. data/lib/pdk/generate/task.rb +11 -10
  74. data/lib/pdk/generate/transport.rb +8 -7
  75. data/lib/pdk/generate.rb +1 -1
  76. data/lib/pdk/logger.rb +3 -2
  77. data/lib/pdk/module/build.rb +34 -49
  78. data/lib/pdk/module/convert.rb +13 -22
  79. data/lib/pdk/module/metadata.rb +53 -61
  80. data/lib/pdk/module/release.rb +19 -25
  81. data/lib/pdk/module/update.rb +4 -13
  82. data/lib/pdk/module/update_manager.rb +18 -25
  83. data/lib/pdk/module.rb +1 -1
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +12 -37
  86. data/lib/pdk/report.rb +4 -4
  87. data/lib/pdk/template/fetcher/git.rb +7 -8
  88. data/lib/pdk/template/fetcher/local.rb +1 -0
  89. data/lib/pdk/template/fetcher.rb +4 -2
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
  91. data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
  92. data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
  93. data/lib/pdk/template/renderer/v1.rb +1 -1
  94. data/lib/pdk/template/renderer.rb +1 -0
  95. data/lib/pdk/template/template_dir.rb +3 -3
  96. data/lib/pdk/template.rb +2 -6
  97. data/lib/pdk/tests/unit.rb +36 -25
  98. data/lib/pdk/util/bundler.rb +10 -14
  99. data/lib/pdk/util/changelog_generator.rb +15 -12
  100. data/lib/pdk/util/env.rb +1 -0
  101. data/lib/pdk/util/filesystem.rb +18 -17
  102. data/lib/pdk/util/git.rb +16 -21
  103. data/lib/pdk/util/json_finder.rb +7 -6
  104. data/lib/pdk/util/puppet_strings.rb +1 -1
  105. data/lib/pdk/util/puppet_version.rb +16 -67
  106. data/lib/pdk/util/ruby_version.rb +9 -13
  107. data/lib/pdk/util/template_uri.rb +17 -29
  108. data/lib/pdk/util/vendored_file.rb +5 -18
  109. data/lib/pdk/util/windows/api_types.rb +70 -64
  110. data/lib/pdk/util/windows/file.rb +31 -27
  111. data/lib/pdk/util/windows/process.rb +59 -61
  112. data/lib/pdk/util/windows/string.rb +19 -12
  113. data/lib/pdk/util.rb +12 -20
  114. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
  115. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
  116. data/lib/pdk/validate/external_command_validator.rb +6 -1
  117. data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
  118. data/lib/pdk/validate/invokable_validator.rb +30 -20
  119. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
  120. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
  121. data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
  122. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
  123. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
  124. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
  125. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
  126. data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
  127. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
  128. data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
  129. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
  130. data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
  131. data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
  132. data/lib/pdk/validate/validator.rb +4 -2
  133. data/lib/pdk/validate/validator_group.rb +6 -3
  134. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
  135. data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
  136. data/lib/pdk/validate.rb +6 -6
  137. data/lib/pdk/version.rb +2 -2
  138. data/lib/pdk.rb +12 -12
  139. metadata +27 -35
  140. data/lib/pdk/cli/config/get.rb +0 -26
  141. data/lib/pdk/cli/config.rb +0 -22
  142. data/lib/pdk/cli/module/build.rb +0 -12
  143. data/lib/pdk/cli/module/generate.rb +0 -47
  144. data/lib/pdk/cli/module.rb +0 -14
@@ -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::CLI
9
- @release_cmd = @base_cmd.define_command do
10
- name 'release'
11
- usage 'release [options]'
12
- summary '(Experimental) Release a module to the Puppet Forge.'
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
- flag nil, :force, 'Release the module automatically, with no prompts.'
15
- flag nil, :'skip-validation', 'Skips the module validation check.'
16
- flag nil, :'skip-changelog', 'Skips the automatic changelog generation.'
17
- flag nil, :'skip-dependency', 'Skips the module dependency check.'
18
- flag nil, :'skip-documentation', 'Skips the documentation update.'
19
- flag nil, :'skip-build', 'Skips module build.'
20
- flag nil, :'skip-publish', 'Skips publishing the module to the forge.'
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
- option nil, :'forge-upload-url', 'Set forge upload url path.',
23
- argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases'
23
+ option nil, :'forge-upload-url', 'Set forge upload url path.',
24
+ argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases'
24
25
 
25
- option nil, :'forge-token', 'Set Forge API token.',
26
- argument: :optional
26
+ option nil, :'forge-token', 'Set Forge API token.',
27
+ argument: :optional
27
28
 
28
- 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.',
29
- argument: :required
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
- 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',
32
- argument: :required
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
- run do |opts, _args, _cmd|
35
- # Make sure build is being run in a valid module directory with a metadata.json
36
- PDK::CLI::Util.ensure_in_module!(
37
- message: '`pdk release` can only be run from inside a valid module with a metadata.json.',
38
- log_level: :info,
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
- Release.prepare_interview(opts) unless opts[:force]
42
+ Release.prepare_interview(opts) unless opts[:force]
42
43
 
43
- Release.send_analytics('release', opts)
44
+ Release.send_analytics('release', opts)
44
45
 
45
- release = PDK::Module::Release.new(nil, opts)
46
+ release = PDK::Module::Release.new(nil, opts)
46
47
 
47
- Release.module_compatibility_checks!(release, opts)
48
+ Release.module_compatibility_checks!(release, opts)
48
49
 
49
- release.run
50
+ release.run
51
+ end
50
52
  end
51
- end
52
53
 
53
- module Release
54
- # Checks whether the module is compatible with PDK release process
55
- # @param release PDK::Module::Release Object representing the release
56
- # @param opts Options Hash from Cri
57
- def self.module_compatibility_checks!(release, opts)
58
- unless release.module_metadata.forge_ready?
59
- if opts[:force]
60
- PDK.logger.warn "This module is missing the following fields in the metadata.json: #{release.module_metadata.missing_fields.join(', ')}. " \
61
- 'These missing fields may affect the visibility of the module on the Forge.'
62
- else
63
- release.module_metadata.interview_for_forge!
64
- release.write_module_metadata!
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
- unless release.pdk_compatible? # rubocop:disable Style/GuardClause Nope!
69
- if opts[:force]
70
- PDK.logger.warn 'This module is not compatible with PDK, so PDK can not validate or test this build.'
71
- else
72
- PDK.logger.info 'This module is not compatible with PDK, so PDK can not validate or test this build. ' \
73
- 'Unvalidated modules may have errors when uploading to the Forge. ' \
74
- 'To make this module PDK compatible and use validate features, cancel the build and run `pdk convert`.'
75
- unless PDK::CLI::Util.prompt_for_yes('Continue build without converting?')
76
- PDK.logger.info 'Build cancelled; exiting.'
77
- PDK::Util.exit_process(1)
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
- # Send_analytics for the given command and Cri options
84
- def self.send_analytics(command, opts)
85
- # Don't pass tokens to analytics
86
- PDK::CLI::Util.analytics_screen_view(command, opts.reject { |k, _| k == :'forge-token' })
87
- end
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
- def self.prepare_interview(opts)
90
- questions = []
90
+ def self.prepare_interview(opts)
91
+ questions = []
91
92
 
92
- unless opts[:'skip-validation']
93
- questions << {
94
- name: 'validation',
95
- question: 'Do you want to run the module validation ?',
96
- type: :yes,
97
- }
98
- end
99
- unless opts[:'skip-changelog']
100
- questions << {
101
- name: 'changelog',
102
- question: 'Do you want to run the automatic changelog generation ?',
103
- type: :yes,
104
- }
105
- end
106
- unless opts[:version]
107
- questions << {
108
- name: 'setversion',
109
- question: 'Do you want to set the module version ?',
110
- type: :yes,
111
- }
112
- end
113
- unless opts[:'skip-dependency']
114
- questions << {
115
- name: 'dependency',
116
- question: 'Do you want to run the dependency-checker on this module?',
117
- type: :yes,
118
- }
119
- end
120
- unless opts[:'skip-documentation']
121
- questions << {
122
- name: 'documentation',
123
- question: 'Do you want to update the documentation for this module?',
124
- type: :yes,
125
- }
126
- end
127
- unless opts[:'skip-publish']
128
- questions << {
129
- name: 'publish',
130
- question: 'Do you want to publish the module on the Puppet Forge?',
131
- type: :yes,
132
- }
133
- end
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
- prompt = TTY::Prompt.new(help_color: :cyan)
136
- interview = PDK::CLI::Util::Interview.new(prompt)
137
- interview.add_questions(questions)
138
- answers = interview.run
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
- unless answers.nil?
141
- opts[:'skip-validation'] = !answers['validation']
142
- opts[:'skip-changelog'] = !answers['changelog']
143
- opts[:'skip-dependency'] = !answers['dependency']
144
- opts[:'skip-documentation'] = !answers['documentation']
145
- opts[:'skip-publish'] = !answers['publish']
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
- prepare_version_interview(prompt, opts) if answers['setversion']
148
+ prepare_version_interview(prompt, opts) if answers['setversion']
148
149
 
149
- prepare_publish_interview(prompt, opts) if answers['publish']
150
+ prepare_publish_interview(prompt, opts) if answers['publish']
151
+ end
152
+ answers
150
153
  end
151
- answers
152
- end
153
154
 
154
- def self.prepare_version_interview(prompt, opts)
155
- questions = [
156
- {
157
- name: 'version',
158
- question: 'Please set the module version',
159
- help: 'This value is the version that will be used in the changelog generator and building of the module.',
160
- required: true,
161
- validate_pattern: %r{(\*|\d+(\.\d+){0,2}(\.\*)?)$}i,
162
- 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.',
163
- },
164
- ]
165
- interview = PDK::CLI::Util::Interview.new(prompt)
166
- interview.add_questions(questions)
167
- ver_answer = interview.run
168
- opts[:version] = ver_answer['version']
169
- end
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
- def self.prepare_publish_interview(prompt, opts)
172
- return if opts[:'forge-token']
173
- questions = [
174
- {
175
- name: 'apikey',
176
- question: 'Please set the api key(authorization token) to upload on the Puppet Forge',
177
- help: 'This value is used for authentication on the Puppet Forge to upload your module tarball.',
178
- required: true,
179
- },
180
- ]
181
- interview = PDK::CLI::Util::Interview.new(prompt)
182
- interview.add_questions(questions)
183
- api_answer = interview.run
184
- opts[:'forge-token'] = api_answer['apikey']
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::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?
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
- force = opts[:force] || false
10
+ force = opts[:force] || false
10
11
 
11
- raise PDK::CLI::ExitWithError, 'Configuration name is required' if item_name.nil?
12
+ raise PDK::CLI::ExitWithError, 'Configuration name is required' if item_name.nil?
12
13
 
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
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
- 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
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
- # FIXME: It'd be nice to shortcircuit deleting default values. This causes the configuration file
24
- # to be saved, even though nothing actually changes
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
- # 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 })
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
- return 0
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
- # 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 })
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 '%{value}' from '%{name}'" % { value: item_value, name: item_name })
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
- # Same output as `get config`
63
- $stdout.puts '%{name}=%{value}' % { name: item_name, value: new_value }
64
- 0
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
- @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>'
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
- option :f, :force, 'Force multi-value configuration settings to be removed instead of emptied.', argument: :forbidden
76
+ option :f, :force, 'Force multi-value configuration settings to be removed instead of emptied.', argument: :forbidden
75
77
 
76
- run do |opts, args, _cmd|
77
- exit PDK::CLI::Remove::Config.run(opts, args)
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
@@ -1,20 +1,22 @@
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'
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
- run do |_opts, args, _cmd|
9
- if args == ['help']
10
- PDK::CLI.run(%w[remove --help])
11
- exit 0
12
- end
9
+ run do |_opts, args, _cmd|
10
+ if args == ['help']
11
+ PDK::CLI.run(['remove', '--help'])
12
+ exit 0
13
+ end
13
14
 
14
- PDK::CLI.run(%w[remove help]) if args.empty?
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'