File: validate-schema

package info (click to toggle)
ruby-brandur-json-schema 0.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 436 kB
  • sloc: ruby: 4,081; makefile: 6
file content (40 lines) | stat: -rwxr-xr-x 1,055 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env ruby

require "optparse"
require_relative "../lib/commands/validate_schema"

def print_usage!
  $stderr.puts "Usage: validate-schema <schema> <data>, ..."
  $stderr.puts "       validate-schema -d <data>, ..."
end

command = Commands::ValidateSchema.new

parser = OptionParser.new { |opts|
  opts.on("-d", "--detect", "Detect schema from $schema") do
    command.detect = true

    # mix in common schemas for convenience
    command.extra_schemas += ["schema.json", "hyper-schema.json"].
      map { |f| File.expand_path(f, __FILE__ + "/../../schemas") }
  end
  opts.on("-s", "--schema SCHEMA", "Additional schema to use for references") do |s|
    command.extra_schemas << s
  end
  opts.on("-f", "--fail-fast", "Abort after encountering the first validation error") do |s|
    command.fail_fast = true
  end
}

parser.parse!
success = command.run(ARGV.dup)

if success
  command.messages.each { |m| $stdout.puts(m) }
elsif !command.errors.empty?
  command.errors.each { |e| $stderr.puts(e) }
  exit(1)
else
  print_usage!
  exit(1)
end