pdk 2.3.0 → 2.4.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 (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1329 -1321
  3. data/LICENSE +201 -201
  4. data/README.md +163 -163
  5. data/exe/pdk +10 -10
  6. data/lib/pdk/analytics/client/google_analytics.rb +143 -143
  7. data/lib/pdk/analytics/client/noop.rb +25 -25
  8. data/lib/pdk/analytics/util.rb +19 -19
  9. data/lib/pdk/analytics.rb +30 -30
  10. data/lib/pdk/answer_file.rb +12 -12
  11. data/lib/pdk/bolt.rb +19 -19
  12. data/lib/pdk/cli/build.rb +82 -82
  13. data/lib/pdk/cli/bundle.rb +48 -48
  14. data/lib/pdk/cli/config/get.rb +26 -26
  15. data/lib/pdk/cli/config.rb +22 -22
  16. data/lib/pdk/cli/console.rb +148 -148
  17. data/lib/pdk/cli/convert.rb +52 -52
  18. data/lib/pdk/cli/env.rb +52 -52
  19. data/lib/pdk/cli/errors.rb +25 -25
  20. data/lib/pdk/cli/exec/command.rb +293 -293
  21. data/lib/pdk/cli/exec/interactive_command.rb +114 -114
  22. data/lib/pdk/cli/exec.rb +84 -84
  23. data/lib/pdk/cli/exec_group.rb +104 -104
  24. data/lib/pdk/cli/get/config.rb +24 -24
  25. data/lib/pdk/cli/get.rb +20 -20
  26. data/lib/pdk/cli/module/build.rb +12 -12
  27. data/lib/pdk/cli/module/generate.rb +47 -47
  28. data/lib/pdk/cli/module.rb +14 -14
  29. data/lib/pdk/cli/new/class.rb +32 -32
  30. data/lib/pdk/cli/new/defined_type.rb +32 -32
  31. data/lib/pdk/cli/new/fact.rb +29 -29
  32. data/lib/pdk/cli/new/function.rb +29 -29
  33. data/lib/pdk/cli/new/module.rb +53 -53
  34. data/lib/pdk/cli/new/provider.rb +29 -29
  35. data/lib/pdk/cli/new/task.rb +34 -34
  36. data/lib/pdk/cli/new/test.rb +52 -52
  37. data/lib/pdk/cli/new/transport.rb +27 -27
  38. data/lib/pdk/cli/new.rb +21 -21
  39. data/lib/pdk/cli/release/prep.rb +39 -39
  40. data/lib/pdk/cli/release/publish.rb +50 -50
  41. data/lib/pdk/cli/release.rb +194 -194
  42. data/lib/pdk/cli/remove/config.rb +80 -80
  43. data/lib/pdk/cli/remove.rb +20 -20
  44. data/lib/pdk/cli/set/config.rb +119 -119
  45. data/lib/pdk/cli/set.rb +20 -20
  46. data/lib/pdk/cli/test/unit.rb +90 -90
  47. data/lib/pdk/cli/test.rb +11 -11
  48. data/lib/pdk/cli/update.rb +64 -64
  49. data/lib/pdk/cli/util/command_redirector.rb +27 -27
  50. data/lib/pdk/cli/util/interview.rb +72 -72
  51. data/lib/pdk/cli/util/option_normalizer.rb +55 -55
  52. data/lib/pdk/cli/util/option_validator.rb +68 -68
  53. data/lib/pdk/cli/util/spinner.rb +13 -13
  54. data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
  55. data/lib/pdk/cli/util.rb +305 -305
  56. data/lib/pdk/cli/validate.rb +116 -116
  57. data/lib/pdk/cli.rb +175 -175
  58. data/lib/pdk/config/analytics_schema.json +26 -26
  59. data/lib/pdk/config/errors.rb +5 -5
  60. data/lib/pdk/config/ini_file.rb +183 -183
  61. data/lib/pdk/config/ini_file_setting.rb +39 -39
  62. data/lib/pdk/config/json.rb +34 -34
  63. data/lib/pdk/config/json_schema_namespace.rb +142 -142
  64. data/lib/pdk/config/json_schema_setting.rb +53 -53
  65. data/lib/pdk/config/json_with_schema.rb +49 -49
  66. data/lib/pdk/config/namespace.rb +354 -354
  67. data/lib/pdk/config/setting.rb +135 -135
  68. data/lib/pdk/config/validator.rb +31 -31
  69. data/lib/pdk/config/yaml.rb +46 -46
  70. data/lib/pdk/config/yaml_with_schema.rb +59 -59
  71. data/lib/pdk/config.rb +390 -390
  72. data/lib/pdk/context/control_repo.rb +60 -60
  73. data/lib/pdk/context/module.rb +28 -28
  74. data/lib/pdk/context/none.rb +22 -22
  75. data/lib/pdk/context.rb +99 -99
  76. data/lib/pdk/control_repo.rb +90 -90
  77. data/lib/pdk/generate/defined_type.rb +43 -43
  78. data/lib/pdk/generate/fact.rb +25 -25
  79. data/lib/pdk/generate/function.rb +48 -48
  80. data/lib/pdk/generate/module.rb +352 -352
  81. data/lib/pdk/generate/provider.rb +28 -28
  82. data/lib/pdk/generate/puppet_class.rb +43 -43
  83. data/lib/pdk/generate/puppet_object.rb +232 -232
  84. data/lib/pdk/generate/task.rb +68 -68
  85. data/lib/pdk/generate/transport.rb +33 -33
  86. data/lib/pdk/generate.rb +24 -24
  87. data/lib/pdk/i18n.rb +4 -4
  88. data/lib/pdk/logger.rb +45 -45
  89. data/lib/pdk/module/build.rb +322 -322
  90. data/lib/pdk/module/convert.rb +296 -296
  91. data/lib/pdk/module/metadata.rb +202 -202
  92. data/lib/pdk/module/release.rb +260 -260
  93. data/lib/pdk/module/update.rb +131 -131
  94. data/lib/pdk/module/update_manager.rb +227 -227
  95. data/lib/pdk/module.rb +30 -30
  96. data/lib/pdk/report/event.rb +370 -370
  97. data/lib/pdk/report.rb +121 -121
  98. data/lib/pdk/template/fetcher/git.rb +85 -85
  99. data/lib/pdk/template/fetcher/local.rb +28 -28
  100. data/lib/pdk/template/fetcher.rb +98 -98
  101. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
  102. data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
  103. data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
  104. data/lib/pdk/template/renderer/v1.rb +25 -25
  105. data/lib/pdk/template/renderer.rb +96 -96
  106. data/lib/pdk/template/template_dir.rb +67 -67
  107. data/lib/pdk/template.rb +59 -59
  108. data/lib/pdk/tests/unit.rb +252 -252
  109. data/lib/pdk/util/bundler.rb +259 -259
  110. data/lib/pdk/util/changelog_generator.rb +137 -137
  111. data/lib/pdk/util/env.rb +47 -47
  112. data/lib/pdk/util/filesystem.rb +138 -138
  113. data/lib/pdk/util/git.rb +179 -179
  114. data/lib/pdk/util/json_finder.rb +85 -85
  115. data/lib/pdk/util/puppet_strings.rb +125 -125
  116. data/lib/pdk/util/puppet_version.rb +266 -266
  117. data/lib/pdk/util/ruby_version.rb +179 -179
  118. data/lib/pdk/util/template_uri.rb +295 -295
  119. data/lib/pdk/util/vendored_file.rb +93 -93
  120. data/lib/pdk/util/version.rb +43 -43
  121. data/lib/pdk/util/windows/api_types.rb +82 -82
  122. data/lib/pdk/util/windows/file.rb +36 -36
  123. data/lib/pdk/util/windows/process.rb +79 -79
  124. data/lib/pdk/util/windows/string.rb +16 -16
  125. data/lib/pdk/util/windows.rb +15 -15
  126. data/lib/pdk/util.rb +278 -277
  127. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
  128. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
  129. data/lib/pdk/validate/external_command_validator.rb +208 -208
  130. data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
  131. data/lib/pdk/validate/invokable_validator.rb +228 -228
  132. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
  133. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
  134. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
  135. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
  136. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
  137. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
  138. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
  139. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
  140. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
  141. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
  142. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
  143. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
  144. data/lib/pdk/validate/validator.rb +118 -118
  145. data/lib/pdk/validate/validator_group.rb +104 -104
  146. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
  147. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
  148. data/lib/pdk/validate.rb +94 -94
  149. data/lib/pdk/version.rb +4 -4
  150. data/lib/pdk.rb +76 -76
  151. data/locales/config.yaml +21 -21
  152. data/locales/pdk.pot +2094 -2094
  153. metadata +5 -6
@@ -1,116 +1,116 @@
1
- module PDK::CLI
2
- @validate_cmd = @base_cmd.define_command do
3
- name 'validate'
4
- usage _('validate [validators] [options] [targets]')
5
- summary _('Run static analysis tests.')
6
- description _(
7
- "Run metadata, YAML, Puppet, Ruby, or Tasks validation.\n\n" \
8
- '[validators] is an optional comma-separated list of validators to use. ' \
9
- 'If not specified, all validators are used. ' \
10
- "Note that when using PowerShell, the list of validators must be enclosed in single quotes.\n\n" \
11
- '[targets] is an optional space-separated list of files or directories to be validated. ' \
12
- 'If not specified, validators are run against all applicable files in the module.',
13
- )
14
-
15
- PDK::CLI.puppet_version_options(self)
16
- PDK::CLI.puppet_dev_option(self)
17
- flag nil, :list, _('List all available validators.')
18
- flag :a, 'auto-correct', _('Automatically correct problems where possible.')
19
- flag nil, :parallel, _('Run validations in parallel.')
20
-
21
- run do |opts, args, _cmd|
22
- # Write the context information to the debug log
23
- PDK.context.to_debug_log
24
-
25
- if args == ['help']
26
- PDK::CLI.run(['validate', '--help'])
27
- exit 0
28
- end
29
-
30
- require 'pdk/validate'
31
-
32
- if opts[:list]
33
- PDK::CLI::Util.analytics_screen_view('validate', opts)
34
- PDK.logger.info(_('Available validators: %{validator_names}') % { validator_names: PDK::Validate.validator_names.join(', ') })
35
- exit 0
36
- end
37
-
38
- PDK::CLI::Util.validate_puppet_version_opts(opts)
39
- unless PDK.feature_flag?('controlrepo') || PDK.context.is_a?(PDK::Context::Module)
40
- raise PDK::CLI::ExitWithError.new(_('Code validation can only be run from inside a valid module directory'), log_level: :error)
41
- end
42
-
43
- PDK::CLI::Util.module_version_check if PDK.context.is_a?(PDK::Context::Module)
44
-
45
- # Set the ruby version we're going to use early. Must be set before the validators are created.
46
- # Note that this is a bit of code-smell and should be fixed
47
- puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
48
- PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
49
-
50
- targets = []
51
- validators_to_run = nil
52
- if args[0]
53
- # This may be a single validator, a list of validators, or a target.
54
- if Util::OptionValidator.comma_separated_list?(args[0])
55
- # This is a comma separated list. Treat each item as a validator.
56
- vals = Util::OptionNormalizer.comma_separated_list_to_array(args[0])
57
- validators_to_run = PDK::Validate.validator_names.select { |name| vals.include?(name) }
58
-
59
- vals.reject { |v| PDK::Validate.validator_names.include?(v) }
60
- .each do |v|
61
- PDK.logger.warn(_("Unknown validator '%{v}'. Available validators: %{validators}.") % { v: v, validators: PDK::Validate.validator_names.join(', ') })
62
- end
63
- else
64
- # This is a single item. Check if it's a known validator, or otherwise treat it as a target.
65
- val = PDK::Validate.validator_names.find { |name| args[0] == name }
66
- if val
67
- validators_to_run = [val]
68
- else
69
- targets = [args[0]]
70
- # We now know that no validators were passed, so let the user know we're using all of them by default.
71
- PDK.logger.info(_('Running all available validators...'))
72
- end
73
- end
74
- else
75
- PDK.logger.info(_('Running all available validators...'))
76
- end
77
- validators_to_run = PDK::Validate.validator_names if validators_to_run.nil?
78
-
79
- if validators_to_run.sort == PDK::Validate.validator_names.sort
80
- PDK::CLI::Util.analytics_screen_view('validate', opts)
81
- else
82
- PDK::CLI::Util.analytics_screen_view(['validate', validators_to_run.sort].flatten.join('_'), opts)
83
- end
84
-
85
- # Subsequent arguments are targets.
86
- targets.concat(args.to_a[1..-1]) if args.length > 1
87
-
88
- report = PDK::Report.new
89
- report_formats = if opts[:format]
90
- PDK::CLI::Util::OptionNormalizer.report_formats(opts[:format])
91
- else
92
- [{
93
- method: PDK::Report.default_format,
94
- target: PDK::Report.default_target,
95
- }]
96
- end
97
-
98
- options = targets.empty? ? {} : { targets: targets }
99
- options[:auto_correct] = true if opts[:'auto-correct']
100
- options.merge!(puppet_env[:gemset])
101
-
102
- # Ensure that the bundled gems are up to date and correct Ruby is activated before running any validations.
103
- # Note that if no Gemfile exists, then ensure_bundle! will log a debug message and exit gracefully
104
- require 'pdk/util/bundler'
105
- PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
106
-
107
- exit_code, report = PDK::Validate.invoke_validators_by_name(PDK.context, validators_to_run, opts.fetch(:parallel, false), options)
108
-
109
- report_formats.each do |format|
110
- report.send(format[:method], format[:target])
111
- end
112
-
113
- exit exit_code
114
- end
115
- end
116
- end
1
+ module PDK::CLI
2
+ @validate_cmd = @base_cmd.define_command do
3
+ name 'validate'
4
+ usage _('validate [validators] [options] [targets]')
5
+ summary _('Run static analysis tests.')
6
+ description _(
7
+ "Run metadata, YAML, Puppet, Ruby, or Tasks validation.\n\n" \
8
+ '[validators] is an optional comma-separated list of validators to use. ' \
9
+ 'If not specified, all validators are used. ' \
10
+ "Note that when using PowerShell, the list of validators must be enclosed in single quotes.\n\n" \
11
+ '[targets] is an optional space-separated list of files or directories to be validated. ' \
12
+ 'If not specified, validators are run against all applicable files in the module.',
13
+ )
14
+
15
+ PDK::CLI.puppet_version_options(self)
16
+ PDK::CLI.puppet_dev_option(self)
17
+ flag nil, :list, _('List all available validators.')
18
+ flag :a, 'auto-correct', _('Automatically correct problems where possible.')
19
+ flag nil, :parallel, _('Run validations in parallel.')
20
+
21
+ run do |opts, args, _cmd|
22
+ # Write the context information to the debug log
23
+ PDK.context.to_debug_log
24
+
25
+ if args == ['help']
26
+ PDK::CLI.run(['validate', '--help'])
27
+ exit 0
28
+ end
29
+
30
+ require 'pdk/validate'
31
+
32
+ if opts[:list]
33
+ PDK::CLI::Util.analytics_screen_view('validate', opts)
34
+ PDK.logger.info(_('Available validators: %{validator_names}') % { validator_names: PDK::Validate.validator_names.join(', ') })
35
+ exit 0
36
+ end
37
+
38
+ PDK::CLI::Util.validate_puppet_version_opts(opts)
39
+ unless PDK.feature_flag?('controlrepo') || PDK.context.is_a?(PDK::Context::Module)
40
+ raise PDK::CLI::ExitWithError.new(_('Code validation can only be run from inside a valid module directory'), log_level: :error)
41
+ end
42
+
43
+ PDK::CLI::Util.module_version_check if PDK.context.is_a?(PDK::Context::Module)
44
+
45
+ # Set the ruby version we're going to use early. Must be set before the validators are created.
46
+ # Note that this is a bit of code-smell and should be fixed
47
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
48
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
49
+
50
+ targets = []
51
+ validators_to_run = nil
52
+ if args[0]
53
+ # This may be a single validator, a list of validators, or a target.
54
+ if Util::OptionValidator.comma_separated_list?(args[0])
55
+ # This is a comma separated list. Treat each item as a validator.
56
+ vals = Util::OptionNormalizer.comma_separated_list_to_array(args[0])
57
+ validators_to_run = PDK::Validate.validator_names.select { |name| vals.include?(name) }
58
+
59
+ vals.reject { |v| PDK::Validate.validator_names.include?(v) }
60
+ .each do |v|
61
+ PDK.logger.warn(_("Unknown validator '%{v}'. Available validators: %{validators}.") % { v: v, validators: PDK::Validate.validator_names.join(', ') })
62
+ end
63
+ else
64
+ # This is a single item. Check if it's a known validator, or otherwise treat it as a target.
65
+ val = PDK::Validate.validator_names.find { |name| args[0] == name }
66
+ if val
67
+ validators_to_run = [val]
68
+ else
69
+ targets = [args[0]]
70
+ # We now know that no validators were passed, so let the user know we're using all of them by default.
71
+ PDK.logger.info(_('Running all available validators...'))
72
+ end
73
+ end
74
+ else
75
+ PDK.logger.info(_('Running all available validators...'))
76
+ end
77
+ validators_to_run = PDK::Validate.validator_names if validators_to_run.nil?
78
+
79
+ if validators_to_run.sort == PDK::Validate.validator_names.sort
80
+ PDK::CLI::Util.analytics_screen_view('validate', opts)
81
+ else
82
+ PDK::CLI::Util.analytics_screen_view(['validate', validators_to_run.sort].flatten.join('_'), opts)
83
+ end
84
+
85
+ # Subsequent arguments are targets.
86
+ targets.concat(args.to_a[1..-1]) if args.length > 1
87
+
88
+ report = PDK::Report.new
89
+ report_formats = if opts[:format]
90
+ PDK::CLI::Util::OptionNormalizer.report_formats(opts[:format])
91
+ else
92
+ [{
93
+ method: PDK::Report.default_format,
94
+ target: PDK::Report.default_target,
95
+ }]
96
+ end
97
+
98
+ options = targets.empty? ? {} : { targets: targets }
99
+ options[:auto_correct] = true if opts[:'auto-correct']
100
+ options.merge!(puppet_env[:gemset])
101
+
102
+ # Ensure that the bundled gems are up to date and correct Ruby is activated before running any validations.
103
+ # Note that if no Gemfile exists, then ensure_bundle! will log a debug message and exit gracefully
104
+ require 'pdk/util/bundler'
105
+ PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
106
+
107
+ exit_code, report = PDK::Validate.invoke_validators_by_name(PDK.context, validators_to_run, opts.fetch(:parallel, false), options)
108
+
109
+ report_formats.each do |format|
110
+ report.send(format[:method], format[:target])
111
+ end
112
+
113
+ exit exit_code
114
+ end
115
+ end
116
+ end
data/lib/pdk/cli.rb CHANGED
@@ -1,175 +1,175 @@
1
- require 'cri'
2
-
3
- require 'pdk'
4
- require 'pdk/cli/errors'
5
-
6
- module TTY
7
- autoload :Prompt, 'tty/prompt'
8
-
9
- class Prompt
10
- autoload :Test, 'tty/prompt/test'
11
- end
12
- end
13
-
14
- class Cri::Command::CriExitException
15
- def initialize(is_error:)
16
- @is_error = is_error
17
- PDK.analytics.event('CLI', 'invalid command', label: PDK::CLI.anonymised_args.join(' ')) if error?
18
- end
19
- end
20
-
21
- module PDK::CLI
22
- autoload :Util, 'pdk/cli/util'
23
-
24
- # Attempt to anonymise the raw ARGV array if the command parsing failed.
25
- #
26
- # If an item does not start with '-' but is preceeded by an item that does
27
- # start with '-', assume that these items are an option/value pair and redact
28
- # the value. Any additional values that do not start with '-' that follow an
29
- # option/value pair are assumed to be arguments (rather than subcommand
30
- # names) and are also redacted.
31
- #
32
- # @example
33
- # # Where PDK::CLI.args => ['new', 'plan', '--some', 'value', 'plan_name']
34
- #
35
- # PDK::CLI.anonymised_args
36
- # => ['new', 'plan', '--some', 'redacted', 'redacted']
37
- #
38
- # @return Array[String] the command arguments with any identifying values
39
- # redacted.
40
- def self.anonymised_args
41
- in_args = false
42
- @args.map do |arg|
43
- if arg.start_with?('-')
44
- in_args = true
45
- arg
46
- else
47
- in_args ? 'redacted' : arg
48
- end
49
- end
50
- end
51
-
52
- def self.deprecated_runtime?
53
- Gem::Version.new(RbConfig::CONFIG['ruby_version']) < Gem::Version.new('2.4.0')
54
- end
55
-
56
- def self.run(args)
57
- if deprecated_runtime?
58
- PDK.logger.info(
59
- text: _(
60
- 'Support for Ruby versions older than 2.4 will be dropped in the ' \
61
- 'future PDK 2.0.0 release. We recommend updating your Ruby ' \
62
- 'installation to ensure that you can continue using the latest ' \
63
- 'version of PDK.',
64
- ),
65
- wrap: true,
66
- )
67
- end
68
-
69
- @args = args
70
- PDK::Config.analytics_config_interview! unless PDK::Util::Env['PDK_DISABLE_ANALYTICS'] || PDK::Config.analytics_config_exist?
71
- @base_cmd.run(args)
72
- rescue PDK::CLI::ExitWithError => e
73
- PDK.logger.send(e.log_level, e.message)
74
-
75
- exit e.exit_code
76
- rescue PDK::CLI::FatalError => e
77
- PDK.logger.fatal(e.message) if e.message
78
-
79
- # If FatalError was raised as the result of another exception, send the
80
- # details of that exception to the debug log. If there was no cause
81
- # (FatalError raised on its own outside a rescue block), send the details
82
- # of the FatalError exception to the debug log.
83
- cause = e.cause
84
- if cause.nil?
85
- e.backtrace.each { |line| PDK.logger.debug(line) }
86
- else
87
- PDK.logger.debug("#{cause.class}: #{cause.message}")
88
- cause.backtrace.each { |line| PDK.logger.debug(line) }
89
- end
90
-
91
- exit e.exit_code
92
- end
93
-
94
- def self.template_url_option(dsl)
95
- require 'pdk/util/template_uri'
96
-
97
- desc = _('Specifies the URL to the template to use when creating new modules or classes. (default: %{default_url})') % { default_url: PDK::Util::TemplateURI.default_template_uri }
98
-
99
- dsl.option nil, 'template-url', desc, argument: :required
100
- end
101
-
102
- def self.template_ref_option(dsl)
103
- dsl.option nil, 'template-ref', _('Specifies the template git branch or tag to use when creating new modules or classes.'), argument: :required
104
- end
105
-
106
- def self.skip_interview_option(dsl)
107
- dsl.option nil, 'skip-interview', _('When specified, skips interactive querying of metadata.')
108
- end
109
-
110
- def self.full_interview_option(dsl)
111
- dsl.option nil, 'full-interview', _('When specified, interactive querying of metadata will include all optional questions.')
112
- end
113
-
114
- def self.puppet_version_options(dsl)
115
- dsl.option nil, 'puppet-version', _('Puppet version to run tests or validations against.'), argument: :required
116
- dsl.option nil, 'pe-version', _('Puppet Enterprise version to run tests or validations against.'), argument: :required
117
- end
118
-
119
- def self.puppet_dev_option(dsl)
120
- dsl.option nil,
121
- 'puppet-dev',
122
- _('When specified, PDK will validate or test against the current Puppet source from github.com. To use this option, you must have network access to https://github.com.')
123
- end
124
-
125
- @base_cmd = Cri::Command.define do
126
- name 'pdk'
127
- usage _('pdk command [options]')
128
- summary _('Puppet Development Kit')
129
- description _('The shortest path to better modules.')
130
- default_subcommand 'help'
131
-
132
- flag nil, :version, _('Show version of pdk.') do |_, _|
133
- puts PDK::Util::Version.version_string
134
- exit 0
135
- end
136
-
137
- flag :h, :help, _('Show help for this command.') do |_, c|
138
- puts c.help
139
- exit 0
140
- end
141
-
142
- format_desc = _(
143
- "Specify desired output format. Valid formats are '%{available_formats}'. " \
144
- 'You may also specify a file to which the formatted output is sent, ' \
145
- "for example: '--format=junit:report.xml'. This option may be specified " \
146
- 'multiple times if each option specifies a distinct target file.',
147
- ) % { available_formats: PDK::Report.formats.join("', '") }
148
-
149
- option :f, :format, format_desc, argument: :required, multiple: true do |values|
150
- PDK::CLI::Util::OptionNormalizer.report_formats(values.compact)
151
- end
152
-
153
- flag :d, :debug, _('Enable debug output.') do |_, _|
154
- PDK.logger.enable_debug_output
155
- end
156
- end
157
-
158
- require 'pdk/cli/bundle'
159
- require 'pdk/cli/build'
160
- require 'pdk/cli/config'
161
- require 'pdk/cli/convert'
162
- require 'pdk/cli/env'
163
- require 'pdk/cli/get'
164
- require 'pdk/cli/new'
165
- require 'pdk/cli/set'
166
- require 'pdk/cli/test'
167
- require 'pdk/cli/update'
168
- require 'pdk/cli/validate'
169
- require 'pdk/cli/module'
170
- require 'pdk/cli/console'
171
- require 'pdk/cli/release'
172
- require 'pdk/cli/remove'
173
-
174
- @base_cmd.add_command Cri::Command.new_basic_help
175
- end
1
+ require 'cri'
2
+
3
+ require 'pdk'
4
+ require 'pdk/cli/errors'
5
+
6
+ module TTY
7
+ autoload :Prompt, 'tty/prompt'
8
+
9
+ class Prompt
10
+ autoload :Test, 'tty/prompt/test'
11
+ end
12
+ end
13
+
14
+ class Cri::Command::CriExitException
15
+ def initialize(is_error:)
16
+ @is_error = is_error
17
+ PDK.analytics.event('CLI', 'invalid command', label: PDK::CLI.anonymised_args.join(' ')) if error?
18
+ end
19
+ end
20
+
21
+ module PDK::CLI
22
+ autoload :Util, 'pdk/cli/util'
23
+
24
+ # Attempt to anonymise the raw ARGV array if the command parsing failed.
25
+ #
26
+ # If an item does not start with '-' but is preceeded by an item that does
27
+ # start with '-', assume that these items are an option/value pair and redact
28
+ # the value. Any additional values that do not start with '-' that follow an
29
+ # option/value pair are assumed to be arguments (rather than subcommand
30
+ # names) and are also redacted.
31
+ #
32
+ # @example
33
+ # # Where PDK::CLI.args => ['new', 'plan', '--some', 'value', 'plan_name']
34
+ #
35
+ # PDK::CLI.anonymised_args
36
+ # => ['new', 'plan', '--some', 'redacted', 'redacted']
37
+ #
38
+ # @return Array[String] the command arguments with any identifying values
39
+ # redacted.
40
+ def self.anonymised_args
41
+ in_args = false
42
+ @args.map do |arg|
43
+ if arg.start_with?('-')
44
+ in_args = true
45
+ arg
46
+ else
47
+ in_args ? 'redacted' : arg
48
+ end
49
+ end
50
+ end
51
+
52
+ def self.deprecated_runtime?
53
+ Gem::Version.new(RbConfig::CONFIG['ruby_version']) < Gem::Version.new('2.4.0')
54
+ end
55
+
56
+ def self.run(args)
57
+ if deprecated_runtime?
58
+ PDK.logger.info(
59
+ text: _(
60
+ 'Support for Ruby versions older than 2.4 will be dropped in the ' \
61
+ 'future PDK 2.0.0 release. We recommend updating your Ruby ' \
62
+ 'installation to ensure that you can continue using the latest ' \
63
+ 'version of PDK.',
64
+ ),
65
+ wrap: true,
66
+ )
67
+ end
68
+
69
+ @args = args
70
+ PDK::Config.analytics_config_interview! unless PDK::Util::Env['PDK_DISABLE_ANALYTICS'] || PDK::Config.analytics_config_exist?
71
+ @base_cmd.run(args)
72
+ rescue PDK::CLI::ExitWithError => e
73
+ PDK.logger.send(e.log_level, e.message)
74
+
75
+ exit e.exit_code
76
+ rescue PDK::CLI::FatalError => e
77
+ PDK.logger.fatal(e.message) if e.message
78
+
79
+ # If FatalError was raised as the result of another exception, send the
80
+ # details of that exception to the debug log. If there was no cause
81
+ # (FatalError raised on its own outside a rescue block), send the details
82
+ # of the FatalError exception to the debug log.
83
+ cause = e.cause
84
+ if cause.nil?
85
+ e.backtrace.each { |line| PDK.logger.debug(line) }
86
+ else
87
+ PDK.logger.debug("#{cause.class}: #{cause.message}")
88
+ cause.backtrace.each { |line| PDK.logger.debug(line) }
89
+ end
90
+
91
+ exit e.exit_code
92
+ end
93
+
94
+ def self.template_url_option(dsl)
95
+ require 'pdk/util/template_uri'
96
+
97
+ desc = _('Specifies the URL to the template to use when creating new modules or classes. (default: %{default_url})') % { default_url: PDK::Util::TemplateURI.default_template_uri }
98
+
99
+ dsl.option nil, 'template-url', desc, argument: :required
100
+ end
101
+
102
+ def self.template_ref_option(dsl)
103
+ dsl.option nil, 'template-ref', _('Specifies the template git branch or tag to use when creating new modules or classes.'), argument: :required
104
+ end
105
+
106
+ def self.skip_interview_option(dsl)
107
+ dsl.option nil, 'skip-interview', _('When specified, skips interactive querying of metadata.')
108
+ end
109
+
110
+ def self.full_interview_option(dsl)
111
+ dsl.option nil, 'full-interview', _('When specified, interactive querying of metadata will include all optional questions.')
112
+ end
113
+
114
+ def self.puppet_version_options(dsl)
115
+ dsl.option nil, 'puppet-version', _('Puppet version to run tests or validations against.'), argument: :required
116
+ dsl.option nil, 'pe-version', _('Puppet Enterprise version to run tests or validations against.'), argument: :required
117
+ end
118
+
119
+ def self.puppet_dev_option(dsl)
120
+ dsl.option nil,
121
+ 'puppet-dev',
122
+ _('When specified, PDK will validate or test against the current Puppet source from github.com. To use this option, you must have network access to https://github.com.')
123
+ end
124
+
125
+ @base_cmd = Cri::Command.define do
126
+ name 'pdk'
127
+ usage _('pdk command [options]')
128
+ summary _('Puppet Development Kit')
129
+ description _('The shortest path to better modules.')
130
+ default_subcommand 'help'
131
+
132
+ flag nil, :version, _('Show version of pdk.') do |_, _|
133
+ puts PDK::Util::Version.version_string
134
+ exit 0
135
+ end
136
+
137
+ flag :h, :help, _('Show help for this command.') do |_, c|
138
+ puts c.help
139
+ exit 0
140
+ end
141
+
142
+ format_desc = _(
143
+ "Specify desired output format. Valid formats are '%{available_formats}'. " \
144
+ 'You may also specify a file to which the formatted output is sent, ' \
145
+ "for example: '--format=junit:report.xml'. This option may be specified " \
146
+ 'multiple times if each option specifies a distinct target file.',
147
+ ) % { available_formats: PDK::Report.formats.join("', '") }
148
+
149
+ option :f, :format, format_desc, argument: :required, multiple: true do |values|
150
+ PDK::CLI::Util::OptionNormalizer.report_formats(values.compact)
151
+ end
152
+
153
+ flag :d, :debug, _('Enable debug output.') do |_, _|
154
+ PDK.logger.enable_debug_output
155
+ end
156
+ end
157
+
158
+ require 'pdk/cli/bundle'
159
+ require 'pdk/cli/build'
160
+ require 'pdk/cli/config'
161
+ require 'pdk/cli/convert'
162
+ require 'pdk/cli/env'
163
+ require 'pdk/cli/get'
164
+ require 'pdk/cli/new'
165
+ require 'pdk/cli/set'
166
+ require 'pdk/cli/test'
167
+ require 'pdk/cli/update'
168
+ require 'pdk/cli/validate'
169
+ require 'pdk/cli/module'
170
+ require 'pdk/cli/console'
171
+ require 'pdk/cli/release'
172
+ require 'pdk/cli/remove'
173
+
174
+ @base_cmd.add_command Cri::Command.new_basic_help
175
+ end
@@ -1,26 +1,26 @@
1
- {
2
- "definitions": {},
3
- "$schema": "http://json-schema.org/draft-06/schema#",
4
- "$id": "http://puppet.com/schema/does_not_exist.json",
5
- "type": "object",
6
- "title": "The PDK Analytics YAML Schema",
7
- "properties": {
8
- "disabled": {
9
- "$id": "#/properties/disabled",
10
- "type": "boolean",
11
- "title": "Disabled property",
12
- "examples": [
13
- false
14
- ]
15
- },
16
- "user-id": {
17
- "$id": "#/properties/user-id",
18
- "type": "string",
19
- "title": "The User-id for analytics",
20
- "examples": [
21
- "cb9ed65f-37dc-48d8-9863-8bd09cbb61c7"
22
- ],
23
- "pattern": "^[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}$"
24
- }
25
- }
26
- }
1
+ {
2
+ "definitions": {},
3
+ "$schema": "http://json-schema.org/draft-06/schema#",
4
+ "$id": "http://puppet.com/schema/does_not_exist.json",
5
+ "type": "object",
6
+ "title": "The PDK Analytics YAML Schema",
7
+ "properties": {
8
+ "disabled": {
9
+ "$id": "#/properties/disabled",
10
+ "type": "boolean",
11
+ "title": "Disabled property",
12
+ "examples": [
13
+ false
14
+ ]
15
+ },
16
+ "user-id": {
17
+ "$id": "#/properties/user-id",
18
+ "type": "string",
19
+ "title": "The User-id for analytics",
20
+ "examples": [
21
+ "cb9ed65f-37dc-48d8-9863-8bd09cbb61c7"
22
+ ],
23
+ "pattern": "^[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}$"
24
+ }
25
+ }
26
+ }
@@ -1,5 +1,5 @@
1
- module PDK
2
- class Config
3
- class LoadError < StandardError; end
4
- end
5
- end
1
+ module PDK
2
+ class Config
3
+ class LoadError < StandardError; end
4
+ end
5
+ end