Module: Prmd::CLI::Verify
- Extended by:
- Base
- Defined in:
- lib/prmd/cli/verify.rb
Overview
‘verify’ command module.
Class Method Summary collapse
-
.execute(options = {}) ⇒ void
Executes the ‘verify’ command.
-
.make_parser(options = {}) ⇒ OptionParser
Returns a OptionParser for parsing ‘verify’ command options.
Methods included from Base
execute, make_parser, noop_execute, parse_options, run
Class Method Details
.execute(options = {}) ⇒ void
This method returns an undefined value.
Executes the ‘verify’ command.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/prmd/cli/verify.rb', line 38 def self.execute( = {}) filename = .fetch(:argv).first _, data = try_read(filename) custom_schema = [:custom_schema] errors = Prmd.verify(data, custom_schema: custom_schema) unless errors.empty? errors.map! { |error| "#{filename}: #{error}" } if filename errors.each { |error| $stderr.puts(error) } exit(1) end result = [:yaml] ? data.to_yaml : JSON.pretty_generate(data) write_result result, end |
.make_parser(options = {}) ⇒ OptionParser
Returns a OptionParser for parsing ‘verify’ command options.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/prmd/cli/verify.rb', line 14 def self.make_parser( = {}) binname = .fetch(:bin, 'prmd') OptionParser.new do |opts| opts. = "#{binname} verify [options] <combined schema>" opts.on('-y', '--yaml', 'Generate YAML') do |y| yield :yaml, y end opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n| yield :output_file, n end opts.on('-s', '--custom-schema FILENAME', String, 'Path to custom schema') do |n| yield :custom_schema, n end end end |