Module: Prmd::CLI::Verify

Extended by:
Base
Defined in:
lib/prmd/cli/verify.rb

Overview

‘verify’ command module.

Class Method Summary collapse

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.

Examples:

Usage

Prmd::CLI::Verify.execute(argv: ['schema/api.json'])

Parameters:

  • options (Hash<Symbol, Object>) (defaults to: {})


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/prmd/cli/verify.rb', line 35

def self.execute(options = {})
  filename = options.fetch(:argv).first
  _, data = try_read(filename)
  errors = Prmd.verify(data)
  unless errors.empty?
    errors.map! { |error| "#{filename}: #{error}" } if filename
    errors.each { |error| $stderr.puts(error) }
    exit(1)
  end
  result = options[:yaml] ? data.to_yaml : JSON.pretty_generate(data)
  write_result result, options
end

.make_parser(options = {}) ⇒ OptionParser

Returns a OptionParser for parsing ‘verify’ command options.

Parameters:

  • options (Hash<Symbol, Object>) (defaults to: {})

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/prmd/cli/verify.rb', line 14

def self.make_parser(options = {})
  binname = options.fetch(:bin, 'prmd')

  OptionParser.new do |opts|
    opts.banner = "#{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
  end
end