pdk 1.9.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +744 -711
  3. data/README.md +23 -21
  4. data/lib/pdk/answer_file.rb +3 -112
  5. data/lib/pdk/bolt.rb +20 -0
  6. data/lib/pdk/cli/build.rb +51 -54
  7. data/lib/pdk/cli/bundle.rb +33 -29
  8. data/lib/pdk/cli/console.rb +148 -0
  9. data/lib/pdk/cli/convert.rb +46 -37
  10. data/lib/pdk/cli/env.rb +51 -0
  11. data/lib/pdk/cli/errors.rb +4 -3
  12. data/lib/pdk/cli/exec/command.rb +285 -0
  13. data/lib/pdk/cli/exec/interactive_command.rb +109 -0
  14. data/lib/pdk/cli/exec.rb +32 -201
  15. data/lib/pdk/cli/exec_group.rb +79 -43
  16. data/lib/pdk/cli/get/config.rb +26 -0
  17. data/lib/pdk/cli/get.rb +22 -0
  18. data/lib/pdk/cli/new/class.rb +20 -22
  19. data/lib/pdk/cli/new/defined_type.rb +21 -21
  20. data/lib/pdk/cli/new/fact.rb +27 -0
  21. data/lib/pdk/cli/new/function.rb +27 -0
  22. data/lib/pdk/cli/new/module.rb +40 -29
  23. data/lib/pdk/cli/new/provider.rb +18 -18
  24. data/lib/pdk/cli/new/task.rb +23 -22
  25. data/lib/pdk/cli/new/test.rb +52 -0
  26. data/lib/pdk/cli/new/transport.rb +27 -0
  27. data/lib/pdk/cli/new.rb +15 -9
  28. data/lib/pdk/cli/release/prep.rb +39 -0
  29. data/lib/pdk/cli/release/publish.rb +46 -0
  30. data/lib/pdk/cli/release.rb +185 -0
  31. data/lib/pdk/cli/remove/config.rb +83 -0
  32. data/lib/pdk/cli/remove.rb +22 -0
  33. data/lib/pdk/cli/set/config.rb +121 -0
  34. data/lib/pdk/cli/set.rb +22 -0
  35. data/lib/pdk/cli/test/unit.rb +71 -69
  36. data/lib/pdk/cli/test.rb +9 -8
  37. data/lib/pdk/cli/update.rb +38 -21
  38. data/lib/pdk/cli/util/command_redirector.rb +13 -3
  39. data/lib/pdk/cli/util/interview.rb +25 -9
  40. data/lib/pdk/cli/util/option_normalizer.rb +6 -6
  41. data/lib/pdk/cli/util/option_validator.rb +19 -9
  42. data/lib/pdk/cli/util/spinner.rb +13 -0
  43. data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
  44. data/lib/pdk/cli/util.rb +105 -48
  45. data/lib/pdk/cli/validate.rb +96 -111
  46. data/lib/pdk/cli.rb +134 -87
  47. data/lib/pdk/config/errors.rb +5 -0
  48. data/lib/pdk/config/ini_file.rb +184 -0
  49. data/lib/pdk/config/ini_file_setting.rb +35 -0
  50. data/lib/pdk/config/json.rb +35 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +137 -0
  52. data/lib/pdk/config/json_schema_setting.rb +51 -0
  53. data/lib/pdk/config/json_with_schema.rb +47 -0
  54. data/lib/pdk/config/namespace.rb +362 -0
  55. data/lib/pdk/config/setting.rb +134 -0
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +31 -0
  58. data/lib/pdk/config/yaml.rb +41 -0
  59. data/lib/pdk/config/yaml_with_schema.rb +51 -0
  60. data/lib/pdk/config.rb +304 -0
  61. data/lib/pdk/context/control_repo.rb +61 -0
  62. data/lib/pdk/context/module.rb +28 -0
  63. data/lib/pdk/context/none.rb +22 -0
  64. data/lib/pdk/context.rb +98 -0
  65. data/lib/pdk/control_repo.rb +89 -0
  66. data/lib/pdk/generate/defined_type.rb +27 -33
  67. data/lib/pdk/generate/fact.rb +26 -0
  68. data/lib/pdk/generate/function.rb +49 -0
  69. data/lib/pdk/generate/module.rb +160 -153
  70. data/lib/pdk/generate/provider.rb +16 -69
  71. data/lib/pdk/generate/puppet_class.rb +27 -32
  72. data/lib/pdk/generate/puppet_object.rb +100 -159
  73. data/lib/pdk/generate/task.rb +34 -51
  74. data/lib/pdk/generate/transport.rb +34 -0
  75. data/lib/pdk/generate.rb +21 -8
  76. data/lib/pdk/logger.rb +24 -6
  77. data/lib/pdk/module/build.rb +125 -37
  78. data/lib/pdk/module/convert.rb +146 -65
  79. data/lib/pdk/module/metadata.rb +72 -71
  80. data/lib/pdk/module/release.rb +255 -0
  81. data/lib/pdk/module/update.rb +48 -37
  82. data/lib/pdk/module/update_manager.rb +75 -39
  83. data/lib/pdk/module.rb +10 -2
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +36 -48
  86. data/lib/pdk/report.rb +35 -22
  87. data/lib/pdk/template/fetcher/git.rb +84 -0
  88. data/lib/pdk/template/fetcher/local.rb +29 -0
  89. data/lib/pdk/template/fetcher.rb +100 -0
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +108 -0
  91. data/lib/pdk/template/renderer/v1/renderer.rb +131 -0
  92. data/lib/pdk/template/renderer/v1/template_file.rb +100 -0
  93. data/lib/pdk/template/renderer/v1.rb +25 -0
  94. data/lib/pdk/template/renderer.rb +97 -0
  95. data/lib/pdk/template/template_dir.rb +67 -0
  96. data/lib/pdk/template.rb +52 -0
  97. data/lib/pdk/tests/unit.rb +101 -51
  98. data/lib/pdk/util/bundler.rb +44 -42
  99. data/lib/pdk/util/changelog_generator.rb +138 -0
  100. data/lib/pdk/util/env.rb +48 -0
  101. data/lib/pdk/util/filesystem.rb +139 -2
  102. data/lib/pdk/util/git.rb +108 -8
  103. data/lib/pdk/util/json_finder.rb +86 -0
  104. data/lib/pdk/util/puppet_strings.rb +125 -0
  105. data/lib/pdk/util/puppet_version.rb +71 -87
  106. data/lib/pdk/util/ruby_version.rb +49 -25
  107. data/lib/pdk/util/template_uri.rb +283 -0
  108. data/lib/pdk/util/vendored_file.rb +34 -42
  109. data/lib/pdk/util/version.rb +11 -10
  110. data/lib/pdk/util/windows/api_types.rb +74 -44
  111. data/lib/pdk/util/windows/file.rb +31 -27
  112. data/lib/pdk/util/windows/process.rb +74 -0
  113. data/lib/pdk/util/windows/string.rb +19 -12
  114. data/lib/pdk/util/windows.rb +2 -0
  115. data/lib/pdk/util.rb +111 -124
  116. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
  117. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
  118. data/lib/pdk/validate/external_command_validator.rb +213 -0
  119. data/lib/pdk/validate/internal_ruby_validator.rb +101 -0
  120. data/lib/pdk/validate/invokable_validator.rb +238 -0
  121. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +84 -0
  122. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +76 -0
  123. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
  124. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +131 -0
  125. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
  126. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +38 -0
  127. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +135 -0
  128. data/lib/pdk/validate/puppet/puppet_validator_group.rb +22 -0
  129. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +79 -0
  130. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
  131. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +83 -0
  132. data/lib/pdk/validate/tasks/tasks_name_validator.rb +45 -0
  133. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
  134. data/lib/pdk/validate/validator.rb +120 -0
  135. data/lib/pdk/validate/validator_group.rb +107 -0
  136. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +86 -0
  137. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
  138. data/lib/pdk/validate.rb +86 -12
  139. data/lib/pdk/version.rb +2 -2
  140. data/lib/pdk.rb +60 -10
  141. metadata +138 -100
  142. data/lib/pdk/cli/module/build.rb +0 -14
  143. data/lib/pdk/cli/module/generate.rb +0 -45
  144. data/lib/pdk/cli/module.rb +0 -14
  145. data/lib/pdk/i18n.rb +0 -4
  146. data/lib/pdk/module/templatedir.rb +0 -321
  147. data/lib/pdk/template_file.rb +0 -95
  148. data/lib/pdk/validate/base_validator.rb +0 -215
  149. data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -86
  150. data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -109
  151. data/lib/pdk/validate/metadata_validator.rb +0 -30
  152. data/lib/pdk/validate/puppet/puppet_lint.rb +0 -67
  153. data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -112
  154. data/lib/pdk/validate/puppet_validator.rb +0 -30
  155. data/lib/pdk/validate/ruby/rubocop.rb +0 -77
  156. data/lib/pdk/validate/ruby_validator.rb +0 -29
  157. data/lib/pdk/validate/tasks/metadata_lint.rb +0 -126
  158. data/lib/pdk/validate/tasks/name.rb +0 -88
  159. data/lib/pdk/validate/tasks_validator.rb +0 -33
  160. data/lib/pdk/validate/yaml/syntax.rb +0 -109
  161. data/lib/pdk/validate/yaml_validator.rb +0 -31
  162. data/locales/config.yaml +0 -21
  163. data/locales/pdk.pot +0 -1291
@@ -1,41 +1,52 @@
1
- module PDK::CLI
2
- @new_module_cmd = @new_cmd.define_command do
3
- name 'module'
4
- usage _('module [options] [module_name] [target_dir]')
5
- summary _('Create a new module named [module_name] using given options')
1
+ module PDK
2
+ module CLI
3
+ @new_module_cmd = @new_cmd.define_command do
4
+ name 'module'
5
+ usage 'module [options] [module_name] [target_dir]'
6
+ summary 'Create a new module named [module_name] using given options'
6
7
 
7
- PDK::CLI.template_url_option(self)
8
- PDK::CLI.skip_interview_option(self)
9
- PDK::CLI.full_interview_option(self)
8
+ PDK::CLI.template_url_option(self)
9
+ PDK::CLI.template_ref_option(self)
10
+ PDK::CLI.skip_interview_option(self)
11
+ PDK::CLI.full_interview_option(self)
10
12
 
11
- option nil, 'license', _('Specifies the license this module is written under. ' \
12
- "This should be a identifier from https://spdx.org/licenses/. Common values are 'Apache-2.0', 'MIT', or 'proprietary'."), argument: :required
13
- option nil, 'skip-bundle-install', _('Do not automatically run `bundle install` after creating the module.'), hidden: true
13
+ option nil, 'license', 'Specifies the license this module is written under. ' \
14
+ "This should be a identifier from https://spdx.org/licenses/. Common values are 'Apache-2.0', 'MIT', or 'proprietary'.", argument: :required
15
+ option nil, 'skip-bundle-install', 'Do not automatically run `bundle install` after creating the module.', hidden: true
14
16
 
15
- run do |opts, args, _cmd|
16
- require 'pdk/generate/module'
17
+ run do |opts, args, _cmd|
18
+ require 'pdk/generate/module'
17
19
 
18
- module_name = args[0]
19
- target_dir = args[1]
20
+ module_name = args[0]
21
+ target_dir = args[1]
20
22
 
21
- if opts[:'skip-interview'] && opts[:'full-interview']
22
- PDK.logger.info _('Ignoring --full-interview and continuing with --skip-interview.')
23
- opts[:'full-interview'] = false
24
- end
23
+ PDK::CLI::Util.validate_template_opts(opts)
24
+
25
+ if opts[:'skip-interview'] && opts[:'full-interview']
26
+ PDK.logger.info 'Ignoring --full-interview and continuing with --skip-interview.'
27
+ opts[:'full-interview'] = false
28
+ end
25
29
 
26
- unless module_name.nil? || module_name.empty?
27
- module_name_parts = module_name.split('-', 2)
28
- if module_name_parts.size > 1
29
- opts[:username] = module_name_parts[0]
30
- opts[:module_name] = module_name_parts[1]
30
+ if module_name.nil? || module_name.empty?
31
+ if opts[:'skip-interview']
32
+ raise PDK::CLI::ExitWithError,
33
+ 'You must specify a module name on the command line when running ' \
34
+ 'with --skip-interview.'
35
+ end
31
36
  else
32
- opts[:module_name] = module_name
37
+ module_name_parts = module_name.split('-', 2)
38
+ if module_name_parts.size > 1
39
+ opts[:username] = module_name_parts[0]
40
+ opts[:module_name] = module_name_parts[1]
41
+ else
42
+ opts[:module_name] = module_name
43
+ end
44
+ opts[:target_dir] = target_dir.nil? ? opts[:module_name] : target_dir
33
45
  end
34
- opts[:target_dir] = target_dir.nil? ? opts[:module_name] : target_dir
35
- end
36
46
 
37
- PDK.logger.info(_('Creating new module: %{modname}') % { modname: module_name })
38
- PDK::Generate::Module.invoke(opts)
47
+ PDK.logger.info(format('Creating new module: %{modname}', modname: module_name))
48
+ PDK::Generate::Module.invoke(opts)
49
+ end
39
50
  end
40
51
  end
41
52
  end
@@ -1,27 +1,27 @@
1
- module PDK::CLI
2
- @new_provider_cmd = @new_cmd.define_command do
3
- name 'provider'
4
- usage _('provider [options] <name>')
5
- summary _('[experimental] Create a new ruby provider named <name> using given options')
1
+ module PDK
2
+ module CLI
3
+ @new_provider_cmd = @new_cmd.define_command do
4
+ name 'provider'
5
+ usage 'provider [options] <name>'
6
+ summary '[experimental] Create a new ruby provider named <name> using given options'
6
7
 
7
- PDK::CLI.template_url_option(self)
8
+ run do |opts, args, _cmd|
9
+ PDK::CLI::Util.ensure_in_module!
8
10
 
9
- run do |opts, args, _cmd|
10
- PDK::CLI::Util.ensure_in_module!
11
+ provider_name = args[0]
11
12
 
12
- provider_name = args[0]
13
- module_dir = Dir.pwd
13
+ if provider_name.nil? || provider_name.empty?
14
+ puts command.help
15
+ exit 1
16
+ end
14
17
 
15
- if provider_name.nil? || provider_name.empty?
16
- puts command.help
17
- exit 1
18
- end
18
+ raise PDK::CLI::ExitWithError, format("'%{name}' is not a valid provider name", name: provider_name) unless Util::OptionValidator.valid_provider_name?(provider_name)
19
19
 
20
- unless Util::OptionValidator.valid_provider_name?(provider_name)
21
- raise PDK::CLI::ExitWithError, _("'%{name}' is not a valid provider name") % { name: provider_name }
22
- end
20
+ require 'pdk/generate/provider'
23
21
 
24
- PDK::Generate::Provider.new(module_dir, provider_name, opts).run
22
+ updates = PDK::Generate::Provider.new(PDK.context, provider_name, opts).run
23
+ PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
24
+ end
25
25
  end
26
26
  end
27
27
  end
@@ -1,31 +1,32 @@
1
- module PDK::CLI
2
- @new_task_cmd = @new_cmd.define_command do
3
- name 'task'
4
- usage _('task [options] <name>')
5
- summary _('Create a new task named <name> using given options')
1
+ module PDK
2
+ module CLI
3
+ @new_task_cmd = @new_cmd.define_command do
4
+ name 'task'
5
+ usage 'task [options] <name>'
6
+ summary 'Create a new task named <name> using given options'
6
7
 
7
- PDK::CLI.template_url_option(self)
8
- option nil, :description, _('A short description of the purpose of the task'), argument: :required
8
+ option nil, :description, 'A short description of the purpose of the task', argument: :required
9
9
 
10
- run do |opts, args, _cmd|
11
- PDK::CLI::Util.ensure_in_module!(
12
- message: _('Tasks can only be created from inside a valid module directory.'),
13
- log_level: :info,
14
- )
10
+ run do |opts, args, _cmd|
11
+ require 'pdk/generate/task'
15
12
 
16
- task_name = args[0]
17
- module_dir = Dir.pwd
13
+ PDK::CLI::Util.ensure_in_module!(
14
+ message: 'Tasks can only be created from inside a valid module directory.',
15
+ log_level: :info
16
+ )
18
17
 
19
- if task_name.nil? || task_name.empty?
20
- puts command.help
21
- exit 1
22
- end
18
+ task_name = args[0]
23
19
 
24
- unless Util::OptionValidator.valid_task_name?(task_name)
25
- raise PDK::CLI::ExitWithError, _("'%{name}' is not a valid task name") % { name: task_name }
26
- end
20
+ if task_name.nil? || task_name.empty?
21
+ puts command.help
22
+ exit 1
23
+ end
27
24
 
28
- PDK::Generate::Task.new(module_dir, task_name, opts).run
25
+ raise PDK::CLI::ExitWithError, format("'%{name}' is not a valid task name", name: task_name) unless Util::OptionValidator.valid_task_name?(task_name)
26
+
27
+ updates = PDK::Generate::Task.new(PDK.context, task_name, opts).run
28
+ PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
29
+ end
29
30
  end
30
31
  end
31
32
  end
@@ -0,0 +1,52 @@
1
+ module PDK
2
+ module CLI
3
+ @new_define_cmd = @new_cmd.define_command do
4
+ name 'test'
5
+ usage 'test [options] <name>'
6
+ summary 'Create a new test for the object named <name>'
7
+ flag :u, :unit, 'Create a new unit test.'
8
+ PDK::CLI.puppet_version_options(self)
9
+ PDK::CLI.puppet_dev_option(self)
10
+
11
+ run do |opts, args, _cmd|
12
+ require 'pdk/util/puppet_strings'
13
+ require 'pdk/util/bundler'
14
+
15
+ PDK::CLI::Util.validate_puppet_version_opts(opts)
16
+ PDK::CLI::Util.ensure_in_module!(
17
+ message: 'Tests can only be created from inside a valid module directory.',
18
+ log_level: :info
19
+ )
20
+
21
+ object_name = args[0]
22
+
23
+ if object_name.nil? || object_name.empty?
24
+ puts command.help
25
+ exit 1
26
+ end
27
+
28
+ unless opts[:unit]
29
+ # At a future time, we'll replace this conditional with an interactive
30
+ # question to choose the test type.
31
+ PDK.logger.info 'Test type not specified, assuming unit.'
32
+ opts[:unit] = true
33
+ end
34
+
35
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
36
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
37
+ PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
38
+
39
+ begin
40
+ generator, obj = PDK::Util::PuppetStrings.find_object(object_name)
41
+
42
+ updates = generator.new(PDK.context, obj['name'], opts.merge(spec_only: true)).run
43
+ PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
44
+ rescue PDK::Util::PuppetStrings::NoObjectError
45
+ raise PDK::CLI::ExitWithError, format('Unable to find anything called "%{object}" to generate unit tests for.', object: object_name)
46
+ rescue PDK::Util::PuppetStrings::NoGeneratorError => e
47
+ raise PDK::CLI::ExitWithError, format('PDK does not support generating unit tests for "%{object_type}" objects.', object_type: e.message)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ module PDK
2
+ module CLI
3
+ @new_transport_cmd = @new_cmd.define_command do
4
+ name 'transport'
5
+ usage 'transport [options] <name>'
6
+ summary '[experimental] Create a new ruby transport named <name> using given options'
7
+
8
+ run do |opts, args, _cmd|
9
+ PDK::CLI::Util.ensure_in_module!
10
+
11
+ transport_name = args[0]
12
+
13
+ if transport_name.nil? || transport_name.empty?
14
+ puts command.help
15
+ exit 1
16
+ end
17
+
18
+ raise PDK::CLI::ExitWithError, format("'%{name}' is not a valid transport name", name: transport_name) unless Util::OptionValidator.valid_transport_name?(transport_name)
19
+
20
+ require 'pdk/generate/transport'
21
+
22
+ updates = PDK::Generate::Transport.new(PDK.context, transport_name, opts).run
23
+ PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/pdk/cli/new.rb CHANGED
@@ -1,13 +1,15 @@
1
- module PDK::CLI
2
- @new_cmd = @base_cmd.define_command do
3
- name 'new'
4
- usage _('new <thing> [options]')
5
- summary _('create a new module, etc.')
6
- description _('Creates a new <thing> using relevant options.')
7
- default_subcommand 'help'
8
- end
1
+ module PDK
2
+ module CLI
3
+ @new_cmd = @base_cmd.define_command do
4
+ name 'new'
5
+ usage 'new <thing> [options]'
6
+ summary 'create a new module, etc.'
7
+ description 'Creates a new <thing> using relevant options.'
8
+ default_subcommand 'help'
9
+ end
9
10
 
10
- @new_cmd.add_command Cri::Command.new_basic_help
11
+ @new_cmd.add_command Cri::Command.new_basic_help
12
+ end
11
13
  end
12
14
 
13
15
  require 'pdk/cli/new/class'
@@ -15,3 +17,7 @@ require 'pdk/cli/new/defined_type'
15
17
  require 'pdk/cli/new/module'
16
18
  require 'pdk/cli/new/provider'
17
19
  require 'pdk/cli/new/task'
20
+ require 'pdk/cli/new/test'
21
+ require 'pdk/cli/new/transport'
22
+ require 'pdk/cli/new/fact'
23
+ require 'pdk/cli/new/function'
@@ -0,0 +1,39 @@
1
+ require 'pdk/cli/release'
2
+
3
+ module PDK
4
+ module CLI
5
+ @release_prep_cmd = @release_cmd.define_command do
6
+ name 'prep'
7
+ usage 'prep [options]'
8
+ summary '(Experimental) Performs all the pre-release checks to ensure module is ready to be released'
9
+
10
+ flag nil, :force, 'Prepare the module automatically, with no prompts.'
11
+ flag nil, :'skip-validation', 'Skips the module validation check.'
12
+ flag nil, :'skip-changelog', 'Skips the automatic changelog generation.'
13
+ flag nil, :'skip-dependency', 'Skips the module dependency check.'
14
+ flag nil, :'skip-documentation', 'Skips the documentation update.'
15
+
16
+ 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.',
17
+ argument: :required
18
+
19
+ run do |opts, _args, cmd|
20
+ # Make sure build is being run in a valid module directory with a metadata.json
21
+ PDK::CLI::Util.ensure_in_module!(
22
+ message: "`pdk release #{cmd.name}` can only be run from inside a valid module with a metadata.json.",
23
+ log_level: :info
24
+ )
25
+
26
+ opts[:'skip-build'] = true
27
+ opts[:'skip-publish'] = true
28
+
29
+ Release.prepare_interview(opts) unless opts[:force]
30
+
31
+ release = PDK::Module::Release.new(nil, opts)
32
+
33
+ Release.module_compatibility_checks!(release, opts)
34
+
35
+ release.run
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ require 'pdk/cli/release'
2
+
3
+ module PDK
4
+ module CLI
5
+ @release_publish_cmd = @release_cmd.define_command do
6
+ name 'publish'
7
+ usage 'publish [options] <tarball>'
8
+ summary '(Experimental) Publishes the module <tarball> to the Forge.'
9
+
10
+ flag nil, :force, 'Publish the module automatically, with no prompts.'
11
+
12
+ option nil, :'forge-upload-url', 'Set forge upload url path.',
13
+ argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases'
14
+
15
+ option nil, :'forge-token', 'Set Forge API token (you may also set via environment variable PDK_FORGE_TOKEN)', argument: :required
16
+
17
+ run do |opts, _args, cmd|
18
+ # Make sure build is being run in a valid module directory with a metadata.json
19
+ PDK::CLI::Util.ensure_in_module!(
20
+ message: "`pdk release #{cmd.name}` can only be run from inside a valid module with a metadata.json.",
21
+ log_level: :info
22
+ )
23
+
24
+ opts[:'skip-validation'] = true
25
+ opts[:'skip-changelog'] = true
26
+ opts[:'skip-dependency'] = true
27
+ opts[:'skip-documentation'] = true
28
+ opts[:'skip-build'] = true
29
+ opts[:'skip-versionset'] = true
30
+ opts[:force] = true unless PDK::CLI::Util.interactive?
31
+ opts[:'forge-token'] ||= PDK::Util::Env['PDK_FORGE_TOKEN']
32
+
33
+ if opts[:'forge-token'].nil? || opts[:'forge-token'].empty?
34
+ PDK.logger.error 'You must supply a Forge API token either via `--forge-token` option or PDK_FORGE_TOKEN environment variable.'
35
+ exit 1
36
+ end
37
+
38
+ Release.prepare_publish_interview(TTY::Prompt.new(help_color: :cyan), opts) unless opts[:force]
39
+
40
+ release = PDK::Module::Release.new(nil, opts)
41
+
42
+ release.run
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,185 @@
1
+ require 'pdk/cli/util'
2
+ require 'pdk/validate'
3
+ require 'pdk/util/bundler'
4
+ require 'pdk/cli/util/interview'
5
+ require 'pdk/util/changelog_generator'
6
+ require 'pdk/module/build'
7
+
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.'
14
+
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.'
22
+
23
+ option nil, :'forge-upload-url', 'Set forge upload url path.',
24
+ argument: :required, default: 'https://forgeapi.puppetlabs.com/v3/releases'
25
+
26
+ option nil, :'forge-token', 'Set Forge API token.',
27
+ argument: :optional
28
+
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
31
+
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
34
+
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
+ )
41
+
42
+ Release.prepare_interview(opts) unless opts[:force]
43
+
44
+ release = PDK::Module::Release.new(nil, opts)
45
+
46
+ Release.module_compatibility_checks!(release, opts)
47
+
48
+ release.run
49
+ end
50
+ end
51
+
52
+ module Release
53
+ # Checks whether the module is compatible with PDK release process
54
+ # @param release PDK::Module::Release Object representing the release
55
+ # @param opts Options Hash from Cri
56
+ def self.module_compatibility_checks!(release, opts)
57
+ unless release.module_metadata.forge_ready?
58
+ if opts[:force]
59
+ PDK.logger.warn "This module is missing the following fields in the metadata.json: #{release.module_metadata.missing_fields.join(', ')}. " \
60
+ 'These missing fields may affect the visibility of the module on the Forge.'
61
+ else
62
+ release.module_metadata.interview_for_forge!
63
+ release.write_module_metadata!
64
+ end
65
+ end
66
+
67
+ unless release.pdk_compatible? # rubocop:disable Style/GuardClause Nope!
68
+ if opts[:force]
69
+ PDK.logger.warn 'This module is not compatible with PDK, so PDK can not validate or test this build.'
70
+ else
71
+ PDK.logger.info 'This module is not compatible with PDK, so PDK can not validate or test this build. ' \
72
+ 'Unvalidated modules may have errors when uploading to the Forge. ' \
73
+ 'To make this module PDK compatible and use validate features, cancel the build and run `pdk convert`.'
74
+ unless PDK::CLI::Util.prompt_for_yes('Continue build without converting?')
75
+ PDK.logger.info 'Build cancelled; exiting.'
76
+ PDK::Util.exit_process(1)
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ def self.prepare_interview(opts)
83
+ questions = []
84
+
85
+ unless opts[:'skip-validation']
86
+ questions << {
87
+ name: 'validation',
88
+ question: 'Do you want to run the module validation ?',
89
+ type: :yes
90
+ }
91
+ end
92
+ unless opts[:'skip-changelog']
93
+ questions << {
94
+ name: 'changelog',
95
+ question: 'Do you want to run the automatic changelog generation ?',
96
+ type: :yes
97
+ }
98
+ end
99
+ unless opts[:version]
100
+ questions << {
101
+ name: 'setversion',
102
+ question: 'Do you want to set the module version ?',
103
+ type: :yes
104
+ }
105
+ end
106
+ unless opts[:'skip-dependency']
107
+ questions << {
108
+ name: 'dependency',
109
+ question: 'Do you want to run the dependency-checker on this module?',
110
+ type: :yes
111
+ }
112
+ end
113
+ unless opts[:'skip-documentation']
114
+ questions << {
115
+ name: 'documentation',
116
+ question: 'Do you want to update the documentation for this module?',
117
+ type: :yes
118
+ }
119
+ end
120
+ unless opts[:'skip-publish']
121
+ questions << {
122
+ name: 'publish',
123
+ question: 'Do you want to publish the module on the Puppet Forge?',
124
+ type: :yes
125
+ }
126
+ end
127
+
128
+ prompt = TTY::Prompt.new(help_color: :cyan)
129
+ interview = PDK::CLI::Util::Interview.new(prompt)
130
+ interview.add_questions(questions)
131
+ answers = interview.run
132
+
133
+ unless answers.nil?
134
+ opts[:'skip-validation'] = !answers['validation']
135
+ opts[:'skip-changelog'] = !answers['changelog']
136
+ opts[:'skip-dependency'] = !answers['dependency']
137
+ opts[:'skip-documentation'] = !answers['documentation']
138
+ opts[:'skip-publish'] = !answers['publish']
139
+
140
+ prepare_version_interview(prompt, opts) if answers['setversion']
141
+
142
+ prepare_publish_interview(prompt, opts) if answers['publish']
143
+ end
144
+ answers
145
+ end
146
+
147
+ def self.prepare_version_interview(prompt, opts)
148
+ questions = [
149
+ {
150
+ name: 'version',
151
+ question: 'Please set the module version',
152
+ help: 'This value is the version that will be used in the changelog generator and building of the module.',
153
+ required: true,
154
+ validate_pattern: /(\*|\d+(\.\d+){0,2}(\.\*)?)$/i,
155
+ 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.'
156
+ }
157
+ ]
158
+ interview = PDK::CLI::Util::Interview.new(prompt)
159
+ interview.add_questions(questions)
160
+ ver_answer = interview.run
161
+ opts[:version] = ver_answer['version']
162
+ end
163
+
164
+ def self.prepare_publish_interview(prompt, opts)
165
+ return if opts[:'forge-token']
166
+
167
+ questions = [
168
+ {
169
+ name: 'apikey',
170
+ question: 'Please set the api key(authorization token) to upload on the Puppet Forge',
171
+ help: 'This value is used for authentication on the Puppet Forge to upload your module tarball.',
172
+ required: true
173
+ }
174
+ ]
175
+ interview = PDK::CLI::Util::Interview.new(prompt)
176
+ interview.add_questions(questions)
177
+ api_answer = interview.run
178
+ opts[:'forge-token'] = api_answer['apikey']
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+ require 'pdk/cli/release/prep'
185
+ require 'pdk/cli/release/publish'
@@ -0,0 +1,83 @@
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?
9
+
10
+ force = opts[:force] || false
11
+
12
+ raise PDK::CLI::ExitWithError, 'Configuration name is required' if item_name.nil?
13
+
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)
16
+
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
21
+
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
24
+
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
41
+ end
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)
46
+ end
47
+
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))
60
+ else
61
+ PDK.logger.info(format("Removed '%{name}' which had a value of '%{from}'", name: item_name, from: current_value))
62
+ end
63
+
64
+ # Same output as `get config`
65
+ $stdout.puts format('%{name}=%{value}', name: item_name, value: new_value)
66
+ 0
67
+ end
68
+ end
69
+ end
70
+
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>'
75
+
76
+ option :f, :force, 'Force multi-value configuration settings to be removed instead of emptied.', argument: :forbidden
77
+
78
+ run do |opts, args, _cmd|
79
+ exit PDK::CLI::Remove::Config.run(opts, args)
80
+ end
81
+ end
82
+ end
83
+ end