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,88 +1,88 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- module Tasks
6
- class TasksMetadataLintValidator < InternalRubyValidator
7
- FORGE_SCHEMA_URL = 'https://forgeapi.puppet.com/schemas/task.json'.freeze
8
-
9
- def name
10
- 'task-metadata-lint'
11
- end
12
-
13
- def pattern
14
- contextual_pattern('tasks/*.json')
15
- end
16
-
17
- def spinner_text
18
- _('Checking task metadata style (%{pattern}).') % {
19
- pattern: pattern.join(' '),
20
- }
21
- end
22
-
23
- def schema_file
24
- require 'pdk/util/vendored_file'
25
-
26
- schema = PDK::Util::VendoredFile.new('task.json', FORGE_SCHEMA_URL).read
27
-
28
- JSON.parse(schema)
29
- rescue PDK::Util::VendoredFile::DownloadError => e
30
- raise PDK::CLI::FatalError, e.message
31
- rescue JSON::ParserError
32
- raise PDK::CLI::FatalError, _('Failed to parse Task Metadata Schema file.')
33
- end
34
-
35
- def validate_target(report, target)
36
- unless PDK::Util::Filesystem.readable?(target)
37
- report.add_event(
38
- file: target,
39
- source: name,
40
- state: :failure,
41
- severity: 'error',
42
- message: _('Could not be read.'),
43
- )
44
- return 1
45
- end
46
-
47
- require 'json-schema'
48
- begin
49
- # Need to set the JSON Parser and State Generator to the Native one to be
50
- # compatible with the multi_json adapter.
51
- JSON.parser = JSON::Ext::Parser if defined?(JSON::Ext::Parser)
52
- JSON.generator = JSON::Ext::Generator if defined?(JSON::Ext::Generator)
53
-
54
- begin
55
- errors = JSON::Validator.fully_validate(schema_file, PDK::Util::Filesystem.read_file(target)) || []
56
- rescue JSON::Schema::SchemaError => e
57
- raise PDK::CLI::FatalError, _('Unable to validate Task Metadata. %{error}.') % { error: e.message }
58
- end
59
-
60
- if errors.empty?
61
- report.add_event(
62
- file: target,
63
- source: name,
64
- state: :passed,
65
- severity: 'ok',
66
- )
67
- return 0
68
- else
69
- errors.each do |error|
70
- # strip off the trailing parts that aren't relevant
71
- error = error.split('in schema').first if error.include? 'in schema'
72
-
73
- report.add_event(
74
- file: target,
75
- source: name,
76
- state: :failure,
77
- severity: 'error',
78
- message: error,
79
- )
80
- end
81
- return 1
82
- end
83
- end
84
- end
85
- end
86
- end
87
- end
88
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ module Tasks
6
+ class TasksMetadataLintValidator < InternalRubyValidator
7
+ FORGE_SCHEMA_URL = 'https://forgeapi.puppet.com/schemas/task.json'.freeze
8
+
9
+ def name
10
+ 'task-metadata-lint'
11
+ end
12
+
13
+ def pattern
14
+ contextual_pattern('tasks/*.json')
15
+ end
16
+
17
+ def spinner_text
18
+ _('Checking task metadata style (%{pattern}).') % {
19
+ pattern: pattern.join(' '),
20
+ }
21
+ end
22
+
23
+ def schema_file
24
+ require 'pdk/util/vendored_file'
25
+
26
+ schema = PDK::Util::VendoredFile.new('task.json', FORGE_SCHEMA_URL).read
27
+
28
+ JSON.parse(schema)
29
+ rescue PDK::Util::VendoredFile::DownloadError => e
30
+ raise PDK::CLI::FatalError, e.message
31
+ rescue JSON::ParserError
32
+ raise PDK::CLI::FatalError, _('Failed to parse Task Metadata Schema file.')
33
+ end
34
+
35
+ def validate_target(report, target)
36
+ unless PDK::Util::Filesystem.readable?(target)
37
+ report.add_event(
38
+ file: target,
39
+ source: name,
40
+ state: :failure,
41
+ severity: 'error',
42
+ message: _('Could not be read.'),
43
+ )
44
+ return 1
45
+ end
46
+
47
+ require 'json-schema'
48
+ begin
49
+ # Need to set the JSON Parser and State Generator to the Native one to be
50
+ # compatible with the multi_json adapter.
51
+ JSON.parser = JSON::Ext::Parser if defined?(JSON::Ext::Parser)
52
+ JSON.generator = JSON::Ext::Generator if defined?(JSON::Ext::Generator)
53
+
54
+ begin
55
+ errors = JSON::Validator.fully_validate(schema_file, PDK::Util::Filesystem.read_file(target)) || []
56
+ rescue JSON::Schema::SchemaError => e
57
+ raise PDK::CLI::FatalError, _('Unable to validate Task Metadata. %{error}.') % { error: e.message }
58
+ end
59
+
60
+ if errors.empty?
61
+ report.add_event(
62
+ file: target,
63
+ source: name,
64
+ state: :passed,
65
+ severity: 'ok',
66
+ )
67
+ return 0
68
+ else
69
+ errors.each do |error|
70
+ # strip off the trailing parts that aren't relevant
71
+ error = error.split('in schema').first if error.include? 'in schema'
72
+
73
+ report.add_event(
74
+ file: target,
75
+ source: name,
76
+ state: :failure,
77
+ severity: 'error',
78
+ message: error,
79
+ )
80
+ end
81
+ return 1
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -1,50 +1,50 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- module Tasks
6
- class TasksNameValidator < InternalRubyValidator
7
- INVALID_TASK_MSG = _(
8
- 'Invalid task name. Task names must start with a lowercase letter ' \
9
- 'and can only contain lowercase letters, numbers, and underscores.',
10
- )
11
-
12
- def name
13
- 'task-name'
14
- end
15
-
16
- def pattern
17
- contextual_pattern('tasks/**/*')
18
- end
19
-
20
- def spinner_text
21
- _('Checking task names (%{pattern}).') % {
22
- pattern: pattern.join(' '),
23
- }
24
- end
25
-
26
- def validate_target(report, target)
27
- task_name = File.basename(target, File.extname(target))
28
- if PDK::CLI::Util::OptionValidator.valid_task_name?(task_name)
29
- report.add_event(
30
- file: target,
31
- source: name,
32
- state: :passed,
33
- severity: 'ok',
34
- )
35
- return 0
36
- else
37
- report.add_event(
38
- file: target,
39
- source: name,
40
- state: :failure,
41
- severity: 'error',
42
- message: INVALID_TASK_MSG,
43
- )
44
- return 1
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ module Tasks
6
+ class TasksNameValidator < InternalRubyValidator
7
+ INVALID_TASK_MSG = _(
8
+ 'Invalid task name. Task names must start with a lowercase letter ' \
9
+ 'and can only contain lowercase letters, numbers, and underscores.',
10
+ )
11
+
12
+ def name
13
+ 'task-name'
14
+ end
15
+
16
+ def pattern
17
+ contextual_pattern('tasks/**/*')
18
+ end
19
+
20
+ def spinner_text
21
+ _('Checking task names (%{pattern}).') % {
22
+ pattern: pattern.join(' '),
23
+ }
24
+ end
25
+
26
+ def validate_target(report, target)
27
+ task_name = File.basename(target, File.extname(target))
28
+ if PDK::CLI::Util::OptionValidator.valid_task_name?(task_name)
29
+ report.add_event(
30
+ file: target,
31
+ source: name,
32
+ state: :passed,
33
+ severity: 'ok',
34
+ )
35
+ return 0
36
+ else
37
+ report.add_event(
38
+ file: target,
39
+ source: name,
40
+ state: :failure,
41
+ severity: 'error',
42
+ message: INVALID_TASK_MSG,
43
+ )
44
+ return 1
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,20 +1,20 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- module Tasks
6
- class TasksValidatorGroup < ValidatorGroup
7
- def name
8
- 'tasks'
9
- end
10
-
11
- def validators
12
- [
13
- TasksNameValidator,
14
- TasksMetadataLintValidator,
15
- ].freeze
16
- end
17
- end
18
- end
19
- end
20
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ module Tasks
6
+ class TasksValidatorGroup < ValidatorGroup
7
+ def name
8
+ 'tasks'
9
+ end
10
+
11
+ def validators
12
+ [
13
+ TasksNameValidator,
14
+ TasksMetadataLintValidator,
15
+ ].freeze
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,118 +1,118 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Validate
5
- # The base Validator class which all other validators should inherit from.
6
- # Acutal validator implementation should inherit from other child abstract classes e.g. ValidatorGroup or ExternalCommandValdiator
7
- # @abstract
8
- class Validator
9
- # A hash of options set when the Validator was instantiated
10
- # @return Hash[Object => Object]
11
- attr_reader :options
12
-
13
- # The PDK context which the validator will be within.
14
- # @return [PDK::Context::AbstractContext] or a subclass PDK::Context::AbstractContext
15
- attr_reader :context
16
-
17
- # Whether the validator is prepared to be invoked.
18
- # This should only be used for testing
19
- #
20
- # @return [Boolean]
21
- #
22
- # @api private
23
- attr_reader :prepared
24
-
25
- # Creates a new Validator
26
- #
27
- # @param context [PDK::Context::AbstractContext] Optional context which specifies where the validation will take place.
28
- # Passing nil will use a None context (PDK::Context::None)
29
- # @param options [Hash] Optional configuration for the Validator
30
- # @option options :parent_validator [PDK::Validate::Validator] The parent validator for this validator.
31
- # Typically used by ValidatorGroup to create trees of Validators for invocation.
32
- def initialize(context = nil, options = {})
33
- if context.nil?
34
- @context = PDK::Context::None.new(nil)
35
- else
36
- raise ArgumentError, _('Expected PDK::Context::AbstractContext but got \'%{klass}\' for context') % { klass: context.class } unless context.is_a?(PDK::Context::AbstractContext)
37
- @context = context
38
- end
39
- @options = options.dup.freeze
40
- @prepared = false
41
- end
42
-
43
- # Whether this Validator can be invoked in this context. By default any Validator can work in any Context
44
- # @return [Boolean]
45
- # @abstract
46
- def valid_in_context?
47
- true
48
- end
49
-
50
- # Returns the text used for the spinner to display to the user while invoking
51
- #
52
- # @return [String]
53
- #
54
- # @abstract
55
- def spinner_text; end
56
-
57
- # Whether Spinners should be enabled for this validator
58
- #
59
- # @return [Boolean]
60
- #
61
- # @api private
62
- # :nocov: .interactive? is tested elsewhere
63
- def spinners_enabled?
64
- PDK::CLI::Util.interactive?
65
- end
66
- # :nocov:
67
-
68
- # The TTY Spinner for this Validator. Returns nil if spinners are disabled for this validator
69
- #
70
- # @return [TTY::Spinner, nil]
71
- #
72
- # @api private
73
- # @abstract
74
- def spinner; end
75
-
76
- # Start the spinner if it exists
77
- # @api private
78
- def start_spinner
79
- spinner.auto_spin unless spinner.nil?
80
- nil
81
- end
82
-
83
- # Stop the spinner if it exists
84
- # @api private
85
- def stop_spinner(success)
86
- return if spinner.nil?
87
- success ? spinner.success : spinner.error
88
- nil
89
- end
90
-
91
- # Name of the Validator
92
- #
93
- # @return [String]
94
- #
95
- # @abstract
96
- def name; end
97
-
98
- # Once off tasks to run prior to invoking
99
- #
100
- # @api private
101
- #
102
- # @abstract
103
- def prepare_invoke!
104
- @prepared = true
105
- end
106
-
107
- # Invokes the validator and returns the exit code
108
- #
109
- # @param report [PDK::Report] Accumulator of events during the invokation of this validator
110
- # and potential child validators
111
- # @abstract
112
- def invoke(_report)
113
- prepare_invoke!
114
- 0
115
- end
116
- end
117
- end
118
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Validate
5
+ # The base Validator class which all other validators should inherit from.
6
+ # Acutal validator implementation should inherit from other child abstract classes e.g. ValidatorGroup or ExternalCommandValdiator
7
+ # @abstract
8
+ class Validator
9
+ # A hash of options set when the Validator was instantiated
10
+ # @return Hash[Object => Object]
11
+ attr_reader :options
12
+
13
+ # The PDK context which the validator will be within.
14
+ # @return [PDK::Context::AbstractContext] or a subclass PDK::Context::AbstractContext
15
+ attr_reader :context
16
+
17
+ # Whether the validator is prepared to be invoked.
18
+ # This should only be used for testing
19
+ #
20
+ # @return [Boolean]
21
+ #
22
+ # @api private
23
+ attr_reader :prepared
24
+
25
+ # Creates a new Validator
26
+ #
27
+ # @param context [PDK::Context::AbstractContext] Optional context which specifies where the validation will take place.
28
+ # Passing nil will use a None context (PDK::Context::None)
29
+ # @param options [Hash] Optional configuration for the Validator
30
+ # @option options :parent_validator [PDK::Validate::Validator] The parent validator for this validator.
31
+ # Typically used by ValidatorGroup to create trees of Validators for invocation.
32
+ def initialize(context = nil, options = {})
33
+ if context.nil?
34
+ @context = PDK::Context::None.new(nil)
35
+ else
36
+ raise ArgumentError, _('Expected PDK::Context::AbstractContext but got \'%{klass}\' for context') % { klass: context.class } unless context.is_a?(PDK::Context::AbstractContext)
37
+ @context = context
38
+ end
39
+ @options = options.dup.freeze
40
+ @prepared = false
41
+ end
42
+
43
+ # Whether this Validator can be invoked in this context. By default any Validator can work in any Context
44
+ # @return [Boolean]
45
+ # @abstract
46
+ def valid_in_context?
47
+ true
48
+ end
49
+
50
+ # Returns the text used for the spinner to display to the user while invoking
51
+ #
52
+ # @return [String]
53
+ #
54
+ # @abstract
55
+ def spinner_text; end
56
+
57
+ # Whether Spinners should be enabled for this validator
58
+ #
59
+ # @return [Boolean]
60
+ #
61
+ # @api private
62
+ # :nocov: .interactive? is tested elsewhere
63
+ def spinners_enabled?
64
+ PDK::CLI::Util.interactive?
65
+ end
66
+ # :nocov:
67
+
68
+ # The TTY Spinner for this Validator. Returns nil if spinners are disabled for this validator
69
+ #
70
+ # @return [TTY::Spinner, nil]
71
+ #
72
+ # @api private
73
+ # @abstract
74
+ def spinner; end
75
+
76
+ # Start the spinner if it exists
77
+ # @api private
78
+ def start_spinner
79
+ spinner.auto_spin unless spinner.nil?
80
+ nil
81
+ end
82
+
83
+ # Stop the spinner if it exists
84
+ # @api private
85
+ def stop_spinner(success)
86
+ return if spinner.nil?
87
+ success ? spinner.success : spinner.error
88
+ nil
89
+ end
90
+
91
+ # Name of the Validator
92
+ #
93
+ # @return [String]
94
+ #
95
+ # @abstract
96
+ def name; end
97
+
98
+ # Once off tasks to run prior to invoking
99
+ #
100
+ # @api private
101
+ #
102
+ # @abstract
103
+ def prepare_invoke!
104
+ @prepared = true
105
+ end
106
+
107
+ # Invokes the validator and returns the exit code
108
+ #
109
+ # @param report [PDK::Report] Accumulator of events during the invokation of this validator
110
+ # and potential child validators
111
+ # @abstract
112
+ def invoke(_report)
113
+ prepare_invoke!
114
+ 0
115
+ end
116
+ end
117
+ end
118
+ end