pdk 2.7.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -3,17 +3,17 @@ require 'pdk'
3
3
  module PDK
4
4
  module Generate
5
5
  class Module
6
- def self.validate_options(opts)
6
+ def self.validate_options(opts = {})
7
7
  require 'pdk/cli/util/option_validator'
8
8
 
9
9
  unless PDK::CLI::Util::OptionValidator.valid_module_name?(opts[:module_name])
10
- error_msg = "'%{module_name}' is not a valid module name.\n" \
11
- 'Module names must begin with a lowercase letter and can only include lowercase letters, digits, and underscores.' % { module_name: opts[:module_name] }
10
+ error_msg = format("'%{module_name}' is not a valid module name.\n" \
11
+ 'Module names must begin with a lowercase letter and can only include lowercase letters, digits, and underscores.', module_name: opts[:module_name])
12
12
  raise PDK::CLI::ExitWithError, error_msg
13
13
  end
14
14
 
15
15
  target_dir = PDK::Util::Filesystem.expand_path(opts[:target_dir])
16
- raise PDK::CLI::ExitWithError, "The destination directory '%{dir}' already exists" % { dir: target_dir } if PDK::Util::Filesystem.exist?(target_dir)
16
+ raise PDK::CLI::ExitWithError, format("The destination directory '%{dir}' already exists", dir: target_dir) if PDK::Util::Filesystem.exist?(target_dir)
17
17
  end
18
18
 
19
19
  def self.invoke(opts = {})
@@ -32,10 +32,8 @@ module PDK
32
32
  test_file = File.join(parent_dir, '.pdk-test-writable')
33
33
  PDK::Util::Filesystem.write_file(test_file, 'This file was created by the Puppet Development Kit to test if this folder was writable, you can safely remove this file.')
34
34
  PDK::Util::Filesystem.rm_f(test_file)
35
- rescue Errno::EACCES
36
- raise PDK::CLI::FatalError, "You do not have permission to write to '%{parent_dir}'" % {
37
- parent_dir: parent_dir,
38
- }
35
+ rescue Errno::EACCES || Errno::EROFS
36
+ raise PDK::CLI::FatalError, format("You do not have permission to write to '%{parent_dir}'", parent_dir: parent_dir)
39
37
  end
40
38
 
41
39
  temp_target_dir = PDK::Util.make_tmpdir_name('pdk-module-target')
@@ -47,10 +45,8 @@ module PDK
47
45
  if template_uri.default? && template_uri.default_ref?
48
46
  PDK.logger.info 'Using the default template-url and template-ref.'
49
47
  else
50
- PDK.logger.info "Using the %{method} template-url and template-ref '%{template_uri}'." % {
51
- method: opts.key?(:'template-url') ? 'specified' : 'saved',
52
- template_uri: template_uri.metadata_format,
53
- }
48
+ PDK.logger.info format("Using the %{method} template-url and template-ref '%{template_uri}'.", method: opts.key?(:'template-url') ? 'specified' : 'saved',
49
+ template_uri: template_uri.metadata_format)
54
50
  end
55
51
 
56
52
  begin
@@ -58,6 +54,7 @@ module PDK
58
54
  PDK::Template.with(template_uri, context) do |template_dir|
59
55
  template_dir.render_new_module(metadata.data['name'], metadata.data) do |relative_file_path, file_content, file_status|
60
56
  next if [:delete, :unmanage].include?(file_status)
57
+
61
58
  file = Pathname.new(temp_target_dir) + relative_file_path
62
59
  file.dirname.mkpath
63
60
  PDK::Util::Filesystem.write_file(file, file_content)
@@ -79,11 +76,11 @@ module PDK
79
76
  # If the user specifies our default template url via the command
80
77
  # line, remove the saved template-url answer so that the template_uri
81
78
  # resolution can find new default URLs in the future.
82
- PDK.config.set(%w[user module_defaults template-url], nil) if opts.key?(:'template-url')
79
+ PDK.config.set(['user', 'module_defaults', 'template-url'], nil) if opts.key?(:'template-url')
83
80
  else
84
81
  # Save the template-url answers if the module was generated using a
85
82
  # template/reference other than ours.
86
- PDK.config.set(%w[user module_defaults template-url], template_uri.metadata_format)
83
+ PDK.config.set(['user', 'module_defaults', 'template-url'], template_uri.metadata_format)
87
84
  end
88
85
 
89
86
  begin
@@ -95,18 +92,11 @@ module PDK
95
92
  end
96
93
  end
97
94
 
98
- PDK.logger.info "Module '%{name}' generated at path '%{path}'." % {
99
- name: opts[:module_name],
100
- path: target_dir,
101
- }
95
+ PDK.logger.info format("Module '%{name}' generated at path '%{path}'.", name: opts[:module_name], path: target_dir)
102
96
  PDK.logger.info "In your module directory, add classes with the 'pdk new class' command."
103
97
  end
104
98
  rescue Errno::EACCES => e
105
- raise PDK::CLI::FatalError, "Failed to move '%{source}' to '%{target}': %{message}" % {
106
- source: temp_target_dir,
107
- target: target_dir,
108
- message: e.message,
109
- }
99
+ raise PDK::CLI::FatalError, format("Failed to move '%{source}' to '%{target}': %{message}", source: temp_target_dir, target: target_dir, message: e.message)
110
100
  end
111
101
  end
112
102
 
@@ -114,13 +104,11 @@ module PDK
114
104
  require 'etc'
115
105
 
116
106
  login = Etc.getlogin || ''
117
- login_clean = login.downcase.gsub(%r{[^0-9a-z]}i, '')
107
+ login_clean = login.downcase.gsub(/[^0-9a-z]/i, '')
118
108
  login_clean = 'username' if login_clean.empty?
119
109
 
120
110
  if login_clean != login
121
- PDK.logger.debug 'Your username is not a valid Forge username. Proceeding with the username %{username}. You can fix this later in metadata.json.' % {
122
- username: login_clean,
123
- }
111
+ PDK.logger.debug format('Your username is not a valid Forge username. Proceeding with the username %{username}. You can fix this later in metadata.json.', username: login_clean)
124
112
  end
125
113
 
126
114
  login_clean
@@ -138,9 +126,15 @@ module PDK
138
126
  PDK.config.with_scoped_value('module_defaults.author') { |val| defaults['author'] = val }
139
127
  PDK.config.with_scoped_value('module_defaults.license') { |val| defaults['license'] = val }
140
128
  defaults['license'] = opts[:license] if opts.key?(:license)
129
+ PDK.config.with_scoped_value('module_defaults.operatingsystem_support') { |val| defaults['operatingsystem_support'] = val }
141
130
 
142
131
  metadata = PDK::Module::Metadata.new(defaults)
143
- module_interview(metadata, opts) unless opts[:'skip-interview']
132
+
133
+ if opts[:'skip-interview']
134
+ metadata.data['operatingsystem_support'] = metadata.data['operatingsystem_support'].map { |val| PDK::Module::Metadata::OPERATING_SYSTEMS[val] }.flatten
135
+ else
136
+ module_interview(metadata, opts)
137
+ end
144
138
 
145
139
  metadata
146
140
  end
@@ -151,16 +145,11 @@ module PDK
151
145
  File.join(target_dir, 'files'),
152
146
  File.join(target_dir, 'manifests'),
153
147
  File.join(target_dir, 'templates'),
154
- File.join(target_dir, 'tasks'),
148
+ File.join(target_dir, 'tasks')
155
149
  ].each do |dir|
156
- begin
157
- PDK::Util::Filesystem.mkdir_p(dir)
158
- rescue SystemCallError => e
159
- raise PDK::CLI::FatalError, "Unable to create directory '%{dir}': %{message}" % {
160
- dir: dir,
161
- message: e.message,
162
- }
163
- end
150
+ PDK::Util::Filesystem.mkdir_p(dir)
151
+ rescue SystemCallError => e
152
+ raise PDK::CLI::FatalError, format("Unable to create directory '%{dir}': %{message}", dir: dir, message: e.message)
164
153
  end
165
154
  end
166
155
 
@@ -170,88 +159,88 @@ module PDK
170
159
 
171
160
  questions = [
172
161
  {
173
- name: 'module_name',
174
- question: 'If you have a name for your module, add it here.',
175
- help: 'This is the name that will be associated with your module, it should be relevant to the modules content.',
176
- required: true,
177
- validate_pattern: %r{\A[a-z][a-z0-9_]*\Z}i,
178
- validate_message: 'Module names must begin with a lowercase letter and can only include lowercase letters, numbers, and underscores.',
162
+ name: 'module_name',
163
+ question: 'If you have a name for your module, add it here.',
164
+ help: 'This is the name that will be associated with your module, it should be relevant to the modules content.',
165
+ required: true,
166
+ validate_pattern: /\A[a-z][a-z0-9_]*\Z/i,
167
+ validate_message: 'Module names must begin with a lowercase letter and can only include lowercase letters, numbers, and underscores.'
179
168
  },
180
169
  {
181
- name: 'forge_username',
182
- question: 'If you have a Puppet Forge username, add it here.',
183
- help: 'We can use this to upload your module to the Forge when it\'s complete.',
184
- required: true,
185
- validate_pattern: %r{\A[a-z0-9]+\Z}i,
170
+ name: 'forge_username',
171
+ question: 'If you have a Puppet Forge username, add it here.',
172
+ help: 'We can use this to upload your module to the Forge when it\'s complete.',
173
+ required: true,
174
+ validate_pattern: /\A[a-z0-9]+\Z/i,
186
175
  validate_message: 'Forge usernames can only contain lowercase letters and numbers',
187
- default: opts[:username],
176
+ default: opts[:username]
188
177
  },
189
178
  {
190
- name: 'version',
191
- question: 'What version is this module?',
192
- help: 'Puppet uses Semantic Versioning (semver.org) to version modules.',
193
- required: true,
194
- validate_pattern: %r{\A[0-9]+\.[0-9]+\.[0-9]+}i,
179
+ name: 'version',
180
+ question: 'What version is this module?',
181
+ help: 'Puppet uses Semantic Versioning (semver.org) to version modules.',
182
+ required: true,
183
+ validate_pattern: /\A[0-9]+\.[0-9]+\.[0-9]+/i,
195
184
  validate_message: 'Semantic Version numbers must be in the form MAJOR.MINOR.PATCH',
196
- default: metadata.data['version'],
197
- forge_only: true,
185
+ default: metadata.data['version'],
186
+ forge_only: true
198
187
  },
199
188
  {
200
- name: 'author',
189
+ name: 'author',
201
190
  question: 'Who wrote this module?',
202
- help: 'This is used to credit the module\'s author.',
191
+ help: 'This is used to credit the module\'s author.',
203
192
  required: true,
204
- default: metadata.data['author'],
193
+ default: metadata.data['author']
205
194
  },
206
195
  {
207
- name: 'license',
196
+ name: 'license',
208
197
  question: 'What license does this module code fall under?',
209
- help: 'This should be an identifier from https://spdx.org/licenses/. Common values are "Apache-2.0", "MIT", or "proprietary".',
198
+ help: 'This should be an identifier from https://spdx.org/licenses/. Common values are "Apache-2.0", "MIT", or "proprietary".',
210
199
  required: true,
211
- default: metadata.data['license'],
200
+ default: metadata.data['license']
212
201
  },
213
202
  {
214
- name: 'operatingsystem_support',
203
+ name: 'operatingsystem_support',
215
204
  question: 'What operating systems does this module support?',
216
- help: 'Use the up and down keys to move between the choices, space to select and enter to continue.',
205
+ help: 'Use the up and down keys to move between the choices, space to select and enter to continue.',
217
206
  required: true,
218
- type: :multi_select,
219
- choices: PDK::Module::Metadata::OPERATING_SYSTEMS,
220
- default: PDK::Module::Metadata::DEFAULT_OPERATING_SYSTEMS.map do |os_name|
207
+ type: :multi_select,
208
+ choices: PDK::Module::Metadata::OPERATING_SYSTEMS,
209
+ default: metadata.data['operatingsystem_support'] do |os_name|
221
210
  # tty-prompt uses a 1-index
222
211
  PDK::Module::Metadata::OPERATING_SYSTEMS.keys.index(os_name) + 1
223
- end,
212
+ end
224
213
  },
225
214
  {
226
- name: 'summary',
227
- question: 'Summarize the purpose of this module in a single sentence.',
228
- help: 'This helps other Puppet users understand what the module does.',
229
- required: true,
230
- default: metadata.data['summary'],
231
- forge_only: true,
215
+ name: 'summary',
216
+ question: 'Summarize the purpose of this module in a single sentence.',
217
+ help: 'This helps other Puppet users understand what the module does.',
218
+ required: true,
219
+ default: metadata.data['summary'],
220
+ forge_only: true
232
221
  },
233
222
  {
234
- name: 'source',
235
- question: 'If there is a source code repository for this module, enter the URL here.',
236
- help: 'Skip this if no repository exists yet. You can update this later in the metadata.json.',
237
- required: true,
238
- default: metadata.data['source'],
239
- forge_only: true,
223
+ name: 'source',
224
+ question: 'If there is a source code repository for this module, enter the URL here.',
225
+ help: 'Skip this if no repository exists yet. You can update this later in the metadata.json.',
226
+ required: true,
227
+ default: metadata.data['source'],
228
+ forge_only: true
240
229
  },
241
230
  {
242
- name: 'project_page',
243
- question: 'If there is a URL where others can learn more about this module, enter it here.',
244
- help: 'Optional. You can update this later in the metadata.json.',
245
- default: metadata.data['project_page'],
246
- forge_only: true,
231
+ name: 'project_page',
232
+ question: 'If there is a URL where others can learn more about this module, enter it here.',
233
+ help: 'Optional. You can update this later in the metadata.json.',
234
+ default: metadata.data['project_page'],
235
+ forge_only: true
247
236
  },
248
237
  {
249
- name: 'issues_url',
250
- question: 'If there is a public issue tracker for this module, enter its URL here.',
251
- help: 'Optional. You can update this later in the metadata.json.',
252
- default: metadata.data['issues_url'],
253
- forge_only: true,
254
- },
238
+ name: 'issues_url',
239
+ question: 'If there is a public issue tracker for this module, enter its URL here.',
240
+ help: 'Optional. You can update this later in the metadata.json.',
241
+ default: metadata.data['issues_url'],
242
+ forge_only: true
243
+ }
255
244
  ]
256
245
 
257
246
  prompt = TTY::Prompt.new(help_color: :cyan)
@@ -260,8 +249,8 @@ module PDK
260
249
 
261
250
  if opts[:only_ask]
262
251
  questions.reject! do |question|
263
- if %w[module_name forge_username].include?(question[:name])
264
- metadata.data['name'] && metadata.data['name'] =~ %r{\A[a-z0-9]+-[a-z][a-z0-9_]*\Z}i
252
+ if ['module_name', 'forge_username'].include?(question[:name])
253
+ metadata.data['name'] && metadata.data['name'] =~ /\A[a-z0-9]+-[a-z][a-z0-9_]*\Z/i
265
254
  else
266
255
  !opts[:only_ask].include?(question[:name])
267
256
  end
@@ -275,15 +264,11 @@ module PDK
275
264
  interview.add_questions(questions)
276
265
 
277
266
  if PDK::Util::Filesystem.file?('metadata.json')
278
- puts "\nWe need to update the metadata.json file for this module, so we\'re going to ask you %{count} " \
279
- "questions.\n" % {
280
- count: interview.num_questions,
281
- }
267
+ puts format("\nWe need to update the metadata.json file for this module, so we're going to ask you %{count} " \
268
+ "questions.\n", count: interview.num_questions)
282
269
  else
283
- puts "\nWe need to create the metadata.json file for this module, so we\'re going to ask you %{count} " \
284
- "questions.\n" % {
285
- count: interview.num_questions,
286
- }
270
+ puts format("\nWe need to create the metadata.json file for this module, so we're going to ask you %{count} " \
271
+ "questions.\n", count: interview.num_questions)
287
272
  end
288
273
 
289
274
  puts 'If the question is not applicable to this module, accept the default option ' \
@@ -320,8 +305,8 @@ module PDK
320
305
 
321
306
  continue = PDK::CLI::Util.prompt_for_yes(
322
307
  'Metadata will be generated based on this information, continue?',
323
- prompt: prompt,
324
- cancel_message: 'Interview cancelled; exiting.',
308
+ prompt: prompt,
309
+ cancel_message: 'Interview cancelled; exiting.'
325
310
  )
326
311
 
327
312
  unless continue
@@ -331,9 +316,9 @@ module PDK
331
316
  end
332
317
 
333
318
  require 'pdk/answer_file'
334
- PDK.config.set(%w[user module_defaults forge_username], opts[:username]) unless opts[:username].nil?
335
- PDK.config.set(%w[user module_defaults author], answers['author']) unless answers['author'].nil?
336
- PDK.config.set(%w[user module_defaults license], answers['license']) unless answers['license'].nil?
319
+ PDK.config.set(['user', 'module_defaults', 'forge_username'], opts[:username]) unless opts[:username].nil?
320
+ PDK.config.set(['user', 'module_defaults', 'author'], answers['author']) unless answers['author'].nil?
321
+ PDK.config.set(['user', 'module_defaults', 'license'], answers['license']) unless answers['license'].nil?
337
322
  end
338
323
  end
339
324
  end
@@ -9,13 +9,14 @@ module PDK
9
9
 
10
10
  def template_files
11
11
  files = {
12
- 'provider_spec.erb' => File.join('spec', 'unit', 'puppet', 'provider', object_name, object_name) + '_spec.rb',
13
- 'provider_type_spec.erb' => File.join('spec', 'unit', 'puppet', 'type', object_name) + '_spec.rb',
12
+ 'provider_spec.erb' => "#{File.join('spec', 'unit', 'puppet', 'provider', object_name, object_name)}_spec.rb",
13
+ 'provider_type_spec.erb' => "#{File.join('spec', 'unit', 'puppet', 'type', object_name)}_spec.rb"
14
14
  }
15
15
  return files if spec_only?
16
+
16
17
  files.merge(
17
- 'provider.erb' => File.join('lib', 'puppet', 'provider', object_name, object_name) + '.rb',
18
- 'provider_type.erb' => File.join('lib', 'puppet', 'type', object_name) + '.rb',
18
+ 'provider.erb' => "#{File.join('lib', 'puppet', 'provider', object_name, object_name)}.rb",
19
+ 'provider_type.erb' => "#{File.join('lib', 'puppet', 'type', object_name)}.rb"
19
20
  )
20
21
  end
21
22
 
@@ -25,12 +25,12 @@ module PDK
25
25
  class_name_parts = object_name.split('::')
26
26
  # Drop the module name if the object name contains multiple parts
27
27
  class_name_parts.delete_at(0) if class_name_parts.length > 1
28
- files = { 'class_spec.erb' => File.join('spec', 'classes', *class_name_parts) + '_spec.rb' }
28
+ files = { 'class_spec.erb' => "#{File.join('spec', 'classes', *class_name_parts)}_spec.rb" }
29
29
  return files if spec_only?
30
30
 
31
- class_name_parts = object_name.split('::')[1..-1]
31
+ class_name_parts = object_name.split('::')[1..]
32
32
  class_name_parts << 'init' if class_name_parts.empty?
33
- files['class.erb'] = File.join('manifests', *class_name_parts) + '.pp'
33
+ files['class.erb'] = "#{File.join('manifests', *class_name_parts)}.pp"
34
34
 
35
35
  files
36
36
  end
@@ -3,9 +3,7 @@ require 'pdk'
3
3
  module PDK
4
4
  module Generate
5
5
  class PuppetObject
6
- attr_reader :context
7
- attr_reader :object_name
8
- attr_reader :options
6
+ attr_reader :context, :object_name, :options
9
7
 
10
8
  # Initialises the PDK::Generate::PuppetObject object.
11
9
  #
@@ -21,7 +19,8 @@ module PDK
21
19
  # @param object_name [String] The name of the object.
22
20
  # @param options [Hash{Symbol => Object}]
23
21
  def initialize(context, object_name, options)
24
- raise ArgumentError, 'Expected PDK::Context::AbstractContext but got \'%{klass}\' for context' % { klass: context.class } unless context.is_a?(PDK::Context::AbstractContext)
22
+ raise ArgumentError, format('Expected PDK::Context::AbstractContext but got \'%{klass}\' for context', klass: context.class) unless context.is_a?(PDK::Context::AbstractContext)
23
+
25
24
  @context = context
26
25
  @options = options
27
26
  @object_name = object_name
@@ -61,7 +60,7 @@ module PDK
61
60
  # @return [void]
62
61
  # @abstract
63
62
  def check_preconditions
64
- raise ArgumentError, 'Expected a module context but got %{context_name}' % { context_name: context.display_name } unless context.is_a?(PDK::Context::Module)
63
+ raise ArgumentError, format('Expected a module context but got %{context_name}', context_name: context.display_name) unless context.is_a?(PDK::Context::Module)
65
64
  end
66
65
 
67
66
  # Check the preconditions of this template group, behaving as a predicate rather than raising an exception.
@@ -122,11 +121,9 @@ module PDK
122
121
  def stage_change(relative_dest_path, content, update_manager)
123
122
  absolute_file_path = File.join(context.root_path, relative_dest_path)
124
123
  if PDK::Util::Filesystem.exist?(absolute_file_path)
125
- raise PDK::CLI::ExitWithError, "Unable to generate %{object_type}; '%{file}' already exists." % {
126
- file: absolute_file_path,
127
- object_type: spec_only? ? 'unit test' : friendly_name,
128
- }
124
+ raise PDK::CLI::ExitWithError, format("Unable to generate %{object_type}; '%{file}' already exists.", file: absolute_file_path, object_type: spec_only? ? 'unit test' : friendly_name)
129
125
  end
126
+
130
127
  update_manager.add_file(absolute_file_path, content)
131
128
  end
132
129
 
@@ -160,7 +157,7 @@ module PDK
160
157
 
161
158
  templates.each do |template|
162
159
  if template[:uri].nil?
163
- PDK.logger.debug('No %{dir_type} template found; trying next template directory.' % { dir_type: template[:type] })
160
+ PDK.logger.debug(format('No %{dir_type} template found; trying next template directory.', dir_type: template[:type]))
164
161
  next
165
162
  end
166
163
 
@@ -170,9 +167,9 @@ module PDK
170
167
  # TODO: refactor to a search-and-execute form instead
171
168
  return # work is done # rubocop:disable Lint/NonLocalExitFromIterator
172
169
  elsif template[:allow_fallback]
173
- PDK.logger.debug('Unable to find a %{type} template in %{url}; trying next template directory.' % { type: friendly_name, url: template[:uri] })
170
+ PDK.logger.debug(format('Unable to find a %{type} template in %{url}; trying next template directory.', type: friendly_name, url: template[:uri]))
174
171
  else
175
- raise PDK::CLI::FatalError, 'Unable to find the %{type} template in %{url}.' % { type: friendly_name, url: template[:uri] }
172
+ raise PDK::CLI::FatalError, format('Unable to find the %{type} template in %{url}.', type: friendly_name, url: template[:uri])
176
173
  end
177
174
  end
178
175
  end
@@ -9,14 +9,15 @@ module PDK
9
9
 
10
10
  def template_files
11
11
  return {} if spec_only?
12
+
12
13
  {
13
- 'task.erb' => File.join('tasks', task_name + '.sh'),
14
+ 'task.erb' => File.join('tasks', "#{task_name}.sh")
14
15
  }
15
16
  end
16
17
 
17
18
  def template_data
18
19
  {
19
- name: object_name,
20
+ name: object_name
20
21
  }
21
22
  end
22
23
 
@@ -29,17 +30,17 @@ module PDK
29
30
  super
30
31
 
31
32
  error = "A task named '%{name}' already exists in this module; defined in %{file}"
32
- allowed_extensions = %w[.md .conf]
33
+ allowed_extensions = ['.md', '.conf']
33
34
 
34
- PDK::Util::Filesystem.glob(File.join(context.root_path, 'tasks', task_name + '.*')).each do |file|
35
+ PDK::Util::Filesystem.glob(File.join(context.root_path, 'tasks', "#{task_name}.*")).each do |file|
35
36
  next if allowed_extensions.include?(File.extname(file))
36
37
 
37
- raise PDK::CLI::ExitWithError, error % { name: task_name, file: file }
38
+ raise PDK::CLI::ExitWithError, format(error, name: task_name, file: file)
38
39
  end
39
40
  end
40
41
 
41
42
  def non_template_files
42
- task_metadata_file = File.join('tasks', task_name + '.json')
43
+ task_metadata_file = File.join('tasks', "#{task_name}.json")
43
44
  { task_metadata_file => JSON.pretty_generate(task_metadata) }
44
45
  end
45
46
 
@@ -52,15 +53,15 @@ module PDK
52
53
  #
53
54
  # @api private
54
55
  def task_name
55
- (object_name == module_name) ? 'init' : object_name
56
+ object_name == module_name ? 'init' : object_name
56
57
  end
57
58
 
58
59
  def task_metadata
59
60
  {
60
61
  puppet_task_version: 1,
61
- supports_noop: false,
62
- description: options.fetch(:description, 'A short description of this task'),
63
- parameters: {},
62
+ supports_noop: false,
63
+ description: options.fetch(:description, 'A short description of this task'),
64
+ parameters: {}
64
65
  }
65
66
  end
66
67
  end
@@ -8,24 +8,25 @@ module PDK
8
8
  end
9
9
 
10
10
  def template_files
11
- # Note : Due to how the V1 templates work, the names of the source template files may be mismatched to
11
+ # NOTE: Due to how the V1 templates work, the names of the source template files may be mismatched to
12
12
  # their destination, e.g. transport_type.erb is really a transport schema
13
13
  files = {
14
- 'transport_spec.erb' => File.join('spec', 'unit', 'puppet', 'transport', object_name) + '_spec.rb',
15
- 'transport_type_spec.erb' => File.join('spec', 'unit', 'puppet', 'transport', 'schema', object_name) + '_spec.rb',
14
+ 'transport_spec.erb' => "#{File.join('spec', 'unit', 'puppet', 'transport', object_name)}_spec.rb",
15
+ 'transport_type_spec.erb' => "#{File.join('spec', 'unit', 'puppet', 'transport', 'schema', object_name)}_spec.rb"
16
16
  }
17
17
  return files if spec_only?
18
+
18
19
  files.merge(
19
- 'transport.erb' => File.join('lib', 'puppet', 'transport', object_name) + '.rb',
20
- 'transport_device.erb' => File.join('lib', 'puppet', 'util', 'network_device', object_name, 'device.rb'),
21
- 'transport_type.erb' => File.join('lib', 'puppet', 'transport', 'schema', object_name) + '.rb',
20
+ 'transport.erb' => "#{File.join('lib', 'puppet', 'transport', object_name)}.rb",
21
+ 'transport_device.erb' => File.join('lib', 'puppet', 'util', 'network_device', object_name, 'device.rb'),
22
+ 'transport_type.erb' => "#{File.join('lib', 'puppet', 'transport', 'schema', object_name)}.rb"
22
23
  )
23
24
  end
24
25
 
25
26
  def template_data
26
27
  {
27
28
  name: object_name,
28
- transport_class: class_name_from_object_name(object_name),
29
+ transport_class: class_name_from_object_name(object_name)
29
30
  }
30
31
  end
31
32
  end
data/lib/pdk/generate.rb CHANGED
@@ -16,7 +16,7 @@ module PDK
16
16
  PDK::Generate::Provider,
17
17
  PDK::Generate::PuppetClass,
18
18
  PDK::Generate::Task,
19
- PDK::Generate::Transport,
19
+ PDK::Generate::Transport
20
20
  ].freeze
21
21
  end
22
22
  module_function :generators
data/lib/pdk/logger.rb CHANGED
@@ -6,7 +6,7 @@ module PDK
6
6
  WRAP_COLUMN_LIMIT = 78
7
7
 
8
8
  def initialize
9
- super(STDERR)
9
+ super($stderr)
10
10
  @sent_messages = {}
11
11
 
12
12
  # TODO: Decide on output format.
@@ -14,7 +14,7 @@ module PDK
14
14
  prefix = "pdk (#{severity}): "
15
15
  if msg.is_a?(Hash)
16
16
  if msg.fetch(:wrap, false)
17
- wrap_pattern = %r{(.{1,#{WRAP_COLUMN_LIMIT - prefix.length}})(\s+|\Z)}
17
+ wrap_pattern = /(.{1,#{WRAP_COLUMN_LIMIT - prefix.length}})(\s+|\Z)/
18
18
  "#{prefix}#{msg[:text].gsub(wrap_pattern, "\\1\n#{' ' * prefix.length}")}\n"
19
19
  else
20
20
  "#{prefix}#{msg[:text]}\n"
@@ -30,6 +30,7 @@ module PDK
30
30
  def warn_once(*args)
31
31
  hash = args.inspect.hash
32
32
  return if (@sent_messages[::Logger::WARN] ||= {}).key?(hash)
33
+
33
34
  @sent_messages[::Logger::WARN][hash] = true
34
35
  warn(*args)
35
36
  end