class Pfm::Command::Validate
def self.banner
def self.banner banner_headline + validator_list + "\n" end
def self.banner_headline
def self.banner_headline <<-E pfm validate VALIDATOR [options] ble validators: end
def self.validator(name, class_name, description)
def self.validator(name, class_name, description) validators << ValidatorCommand.new(name, class_name, description) end
def self.validator_list
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
def self.validators
def self.validators @validators ||= [] end
def have_validator?(name)
def have_validator?(name) self.class.validators.map { |g| g.name.to_s }.include?(name) end
def initialize(*args)
def initialize(*args) super end
def needs_help?(params)
argument is a valid validator name, like `pfm validate server-build -h`,
"--help". Here we override that behavior such that if the first
In the Base class, this is defined to be true if any args match "-h" or
def needs_help?(params) return false if have_validator?(params[0]) super end
def run(params)
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 # Pfm::Command::Base also handles this error in the same way, but it # does not have access to the correct option parser, so it cannot print # the usage correctly. Therefore, invalid CLI usage needs to be handled # here. err("ERROR: #{e.message}\n") msg(validator.opt_parser) 1 end
def validator_for(arg)
def validator_for(arg) self.class.validators.find { |g| g.name.to_s == arg } end