pdk 1.14.1 → 1.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +155 -2
- data/lib/pdk.rb +28 -19
- data/lib/pdk/answer_file.rb +2 -95
- data/lib/pdk/bolt.rb +19 -0
- data/lib/pdk/cli.rb +4 -5
- data/lib/pdk/cli/bundle.rb +5 -1
- data/lib/pdk/cli/config.rb +3 -1
- data/lib/pdk/cli/config/get.rb +3 -1
- data/lib/pdk/cli/console.rb +1 -1
- data/lib/pdk/cli/convert.rb +16 -10
- data/lib/pdk/cli/exec.rb +2 -1
- data/lib/pdk/cli/exec/command.rb +45 -4
- data/lib/pdk/cli/exec_group.rb +78 -43
- data/lib/pdk/cli/get.rb +20 -0
- data/lib/pdk/cli/get/config.rb +24 -0
- data/lib/pdk/cli/module/build.rb +1 -1
- data/lib/pdk/cli/module/generate.rb +1 -1
- data/lib/pdk/cli/new/class.rb +2 -2
- data/lib/pdk/cli/new/defined_type.rb +2 -2
- data/lib/pdk/cli/new/provider.rb +2 -2
- data/lib/pdk/cli/new/task.rb +2 -2
- data/lib/pdk/cli/new/test.rb +2 -2
- data/lib/pdk/cli/new/transport.rb +2 -2
- data/lib/pdk/cli/release.rb +192 -0
- data/lib/pdk/cli/release/prep.rb +39 -0
- data/lib/pdk/cli/release/publish.rb +40 -0
- data/lib/pdk/cli/remove.rb +20 -0
- data/lib/pdk/cli/remove/config.rb +80 -0
- data/lib/pdk/cli/set.rb +20 -0
- data/lib/pdk/cli/set/config.rb +119 -0
- data/lib/pdk/cli/update.rb +18 -8
- data/lib/pdk/cli/util.rb +7 -3
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
- data/lib/pdk/cli/validate.rb +26 -44
- data/lib/pdk/config.rb +265 -8
- data/lib/pdk/config/ini_file.rb +183 -0
- data/lib/pdk/config/ini_file_setting.rb +39 -0
- data/lib/pdk/config/namespace.rb +26 -6
- data/lib/pdk/config/setting.rb +3 -2
- data/lib/pdk/context.rb +99 -0
- data/lib/pdk/context/control_repo.rb +60 -0
- data/lib/pdk/context/module.rb +28 -0
- data/lib/pdk/context/none.rb +22 -0
- data/lib/pdk/control_repo.rb +90 -0
- data/lib/pdk/generate.rb +1 -0
- data/lib/pdk/generate/defined_type.rb +25 -32
- data/lib/pdk/generate/module.rb +42 -35
- data/lib/pdk/generate/provider.rb +16 -65
- data/lib/pdk/generate/puppet_class.rb +25 -31
- data/lib/pdk/generate/puppet_object.rb +84 -189
- data/lib/pdk/generate/resource_api_object.rb +55 -0
- data/lib/pdk/generate/task.rb +28 -46
- data/lib/pdk/generate/transport.rb +21 -75
- data/lib/pdk/module.rb +1 -1
- data/lib/pdk/module/build.rb +38 -25
- data/lib/pdk/module/convert.rb +61 -42
- data/lib/pdk/module/metadata.rb +1 -3
- data/lib/pdk/module/release.rb +254 -0
- data/lib/pdk/module/update.rb +24 -16
- data/lib/pdk/module/update_manager.rb +8 -1
- data/lib/pdk/report.rb +18 -12
- data/lib/pdk/report/event.rb +6 -3
- data/lib/pdk/template.rb +59 -0
- data/lib/pdk/template/fetcher.rb +98 -0
- data/lib/pdk/template/fetcher/git.rb +85 -0
- data/lib/pdk/template/fetcher/local.rb +28 -0
- data/lib/pdk/template/renderer.rb +96 -0
- data/lib/pdk/template/renderer/v1.rb +25 -0
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
- data/lib/pdk/template/template_dir.rb +67 -0
- data/lib/pdk/tests/unit.rb +5 -0
- data/lib/pdk/util.rb +55 -45
- data/lib/pdk/util/bundler.rb +9 -9
- data/lib/pdk/util/changelog_generator.rb +120 -0
- data/lib/pdk/util/env.rb +28 -11
- data/lib/pdk/util/filesystem.rb +62 -2
- data/lib/pdk/util/git.rb +60 -8
- data/lib/pdk/util/json_finder.rb +84 -0
- data/lib/pdk/util/puppet_strings.rb +3 -3
- data/lib/pdk/util/puppet_version.rb +4 -5
- data/lib/pdk/util/ruby_version.rb +9 -6
- data/lib/pdk/util/template_uri.rb +60 -48
- data/lib/pdk/util/version.rb +4 -4
- data/lib/pdk/validate.rb +79 -25
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
- data/lib/pdk/validate/external_command_validator.rb +208 -0
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
- data/lib/pdk/validate/invokable_validator.rb +215 -0
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
- data/lib/pdk/validate/validator.rb +118 -0
- data/lib/pdk/validate/validator_group.rb +104 -0
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +755 -319
- metadata +66 -24
- data/lib/pdk/module/templatedir.rb +0 -391
- data/lib/pdk/template_file.rb +0 -96
- data/lib/pdk/validate/base_validator.rb +0 -215
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
- data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
- data/lib/pdk/validate/metadata_validator.rb +0 -26
- data/lib/pdk/validate/puppet/puppet_epp.rb +0 -137
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
- data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -137
- data/lib/pdk/validate/puppet_validator.rb +0 -26
- data/lib/pdk/validate/ruby/rubocop.rb +0 -72
- data/lib/pdk/validate/ruby_validator.rb +0 -26
- data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
- data/lib/pdk/validate/tasks/name.rb +0 -90
- data/lib/pdk/validate/tasks_validator.rb +0 -29
- data/lib/pdk/validate/yaml/syntax.rb +0 -125
- data/lib/pdk/validate/yaml_validator.rb +0 -28
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Validate
|
5
|
+
module Puppet
|
6
|
+
class PuppetValidatorGroup < ValidatorGroup
|
7
|
+
def name
|
8
|
+
'puppet'
|
9
|
+
end
|
10
|
+
|
11
|
+
def validators
|
12
|
+
[
|
13
|
+
PuppetSyntaxValidator,
|
14
|
+
PuppetLintValidator,
|
15
|
+
PuppetEPPValidator,
|
16
|
+
].freeze
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Validate
|
5
|
+
module Ruby
|
6
|
+
class RubyRubocopValidator < ExternalCommandValidator
|
7
|
+
def allow_empty_targets?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
'rubocop'
|
13
|
+
end
|
14
|
+
|
15
|
+
def cmd
|
16
|
+
'rubocop'
|
17
|
+
end
|
18
|
+
|
19
|
+
def pattern
|
20
|
+
if context.is_a?(PDK::Context::ControlRepo)
|
21
|
+
['Puppetfile', '**/**.rb']
|
22
|
+
else
|
23
|
+
'**/**.rb'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def spinner_text_for_targets(_targets)
|
28
|
+
_('Checking Ruby code style (%{pattern}).') % { pattern: pattern }
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_options(targets)
|
32
|
+
cmd_options = ['--format', 'json']
|
33
|
+
|
34
|
+
if options[:auto_correct]
|
35
|
+
cmd_options << '--auto-correct'
|
36
|
+
end
|
37
|
+
|
38
|
+
cmd_options.concat(targets)
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_output(report, result, _targets)
|
42
|
+
return if result[:stdout].empty?
|
43
|
+
|
44
|
+
begin
|
45
|
+
json_data = JSON.parse(result[:stdout])
|
46
|
+
rescue JSON::ParserError
|
47
|
+
raise PDK::Validate::ParseOutputError, result[:stdout]
|
48
|
+
end
|
49
|
+
|
50
|
+
return unless json_data.key?('files')
|
51
|
+
|
52
|
+
json_data['files'].each do |file_info|
|
53
|
+
next unless file_info.key?('offenses')
|
54
|
+
result = {
|
55
|
+
file: file_info['path'],
|
56
|
+
source: 'rubocop',
|
57
|
+
}
|
58
|
+
|
59
|
+
if file_info['offenses'].empty?
|
60
|
+
report.add_event(result.merge(state: :passed, severity: :ok))
|
61
|
+
else
|
62
|
+
file_info['offenses'].each do |offense|
|
63
|
+
report.add_event(
|
64
|
+
result.merge(
|
65
|
+
line: offense['location']['line'],
|
66
|
+
column: offense['location']['column'],
|
67
|
+
message: offense['message'],
|
68
|
+
severity: offense['corrected'] ? 'corrected' : offense['severity'],
|
69
|
+
test: offense['cop_name'],
|
70
|
+
state: :failure,
|
71
|
+
),
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +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
|
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
|
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Validate
|
5
|
+
# The base class which should be used by meta-validators, that is, this group executes other validators
|
6
|
+
#
|
7
|
+
# At a minimum, the `name` and `validators` methods should be overridden in the child class
|
8
|
+
#
|
9
|
+
# An example concrete implementation could look like:
|
10
|
+
#
|
11
|
+
# module PDK
|
12
|
+
# module Validate
|
13
|
+
# module Tasks
|
14
|
+
# class TasksValidatorGroup < ValidatorGroup
|
15
|
+
# def name
|
16
|
+
# 'tasks'
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def validators
|
20
|
+
# [
|
21
|
+
# TasksNameValidator,
|
22
|
+
# TasksMetadataLintValidator,
|
23
|
+
# ].freeze
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# @see PDK::Validate::Validator
|
31
|
+
# @abstract
|
32
|
+
class ValidatorGroup < Validator
|
33
|
+
# @see PDK::Validate::Validator.spinner_text
|
34
|
+
def spinner_text
|
35
|
+
_('Running %{name} validators ...') % { name: name }
|
36
|
+
end
|
37
|
+
|
38
|
+
# @see PDK::Validate::Validator.spinner
|
39
|
+
def spinner
|
40
|
+
return nil unless spinners_enabled?
|
41
|
+
return @spinner unless @spinner.nil?
|
42
|
+
require 'pdk/cli/util/spinner'
|
43
|
+
|
44
|
+
@spinner = TTY::Spinner::Multi.new("[:spinner] #{spinner_text}", PDK::CLI::Util.spinner_opts_for_platform)
|
45
|
+
|
46
|
+
# Register the child spinners
|
47
|
+
validator_instances.each do |instance|
|
48
|
+
next if instance.spinner.nil?
|
49
|
+
@spinner.register(instance.spinner)
|
50
|
+
end
|
51
|
+
|
52
|
+
@spinner
|
53
|
+
end
|
54
|
+
|
55
|
+
# Can be overridden by child classes to do their own preparation tasks.
|
56
|
+
# Typically this is not required by a meta-validator though.
|
57
|
+
#
|
58
|
+
# @see PDK::Validate::Validator.prepare_invoke!
|
59
|
+
def prepare_invoke!
|
60
|
+
return if @prepared
|
61
|
+
super
|
62
|
+
|
63
|
+
# Force the spinner to be registered etc.
|
64
|
+
spinner
|
65
|
+
|
66
|
+
# Prepare child validators
|
67
|
+
validator_instances.each { |instance| instance.prepare_invoke! }
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
71
|
+
# A list of Validator classes that this group will run
|
72
|
+
# @return Array[Class] An array of Validator classes (or objects that subclass to it) that this group will execute
|
73
|
+
# @abstract
|
74
|
+
def validators
|
75
|
+
[]
|
76
|
+
end
|
77
|
+
|
78
|
+
# @see PDK::Validate::Validator.invoke
|
79
|
+
def invoke(report)
|
80
|
+
exit_code = 0
|
81
|
+
|
82
|
+
prepare_invoke!
|
83
|
+
start_spinner
|
84
|
+
|
85
|
+
validator_instances.each do |instance|
|
86
|
+
exit_code = instance.invoke(report)
|
87
|
+
break if exit_code != 0
|
88
|
+
end
|
89
|
+
|
90
|
+
stop_spinner(exit_code.zero?)
|
91
|
+
|
92
|
+
exit_code
|
93
|
+
end
|
94
|
+
|
95
|
+
# The instanitated PDK::Validator::Validator classes from the `validators` array
|
96
|
+
# @return Array[PDK::Validator::Validator]
|
97
|
+
# @api private
|
98
|
+
def validator_instances
|
99
|
+
@validator_instances ||= validators.map { |klass| klass.new(context, options.merge(parent_validator: self)) }
|
100
|
+
.select { |instance| instance.valid_in_context? }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|