Class: Pfm::Command::Validate
- Inherits:
-
Base
- Object
- Base
- Pfm::Command::Validate
show all
- Defined in:
- lib/idlc-sdk-pfm/command/validate.rb
Defined Under Namespace
Classes: ValidatorCommand
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#build_base_dir, #build_dir, #build_exists?, #build_setup, #deploy_setup, #deploy_setupv2, #inf_base_dir, #needs_version?, #run_with_default_options, #templates_dir, #verbose?
Methods included from Helpers
debug, err, msg, system_command
Constructor Details
#initialize(*args) ⇒ Validate
pfm validate app path/to/basename –skel=path/to/skeleton –example pfm validate file name [path/to/cookbook_root] (inferred from cwd) –from=source_file
43
44
45
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 43
def initialize(*args)
super
end
|
Class Method Details
.banner ⇒ Object
36
37
38
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 36
def self.banner
banner_headline + validator_list + "\n"
end
|
.banner_headline ⇒ Object
24
25
26
27
28
29
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 24
def self.banner_headline
<<-E
Usage: pfm validate VALIDATOR [options]
Available validators:
E
end
|
.validator(name, class_name, description) ⇒ Object
17
18
19
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 17
def self.validator(name, class_name, description)
validators << ValidatorCommand.new(name, class_name, description)
end
|
.validator_list ⇒ Object
31
32
33
34
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 31
def self.validator_list
justify_size = validators.map { |g| g.name.size }.max + 2
validators.map { |g| " #{g.name.to_s.ljust(justify_size)}#{g.description}" }.join("\n")
end
|
.validators ⇒ Object
13
14
15
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 13
def self.validators
@validators ||= []
end
|
Instance Method Details
#have_validator?(name) ⇒ Boolean
79
80
81
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 79
def have_validator?(name)
self.class.validators.map { |g| g.name.to_s }.include?(name)
end
|
#needs_help?(params) ⇒ Boolean
In the Base class, this is defined to be true if any args match “-h” or “–help”. Here we override that behavior such that if the first argument is a valid validator name, like ‘pfm validate server-build -h`, we delegate the request to the specified validator.
74
75
76
77
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 74
def needs_help?(params)
return false if have_validator?(params[0])
super
end
|
#run(params) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 47
def run(params)
if validator_spec = validator_for(params[0])
params.shift
validator = ValidatorCommands.build(validator_spec.class_name, params)
validator.run
else
msg(banner)
1
end
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
err("ERROR: #{e.message}\n")
msg(validator.opt_parser)
1
end
|
#validator_for(arg) ⇒ Object
66
67
68
|
# File 'lib/idlc-sdk-pfm/command/validate.rb', line 66
def validator_for(arg)
self.class.validators.find { |g| g.name.to_s == arg }
end
|