File: validate-schema

package info (click to toggle)
ruby-brandur-json-schema 0.19.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 376 kB
  • sloc: ruby: 3,764; makefile: 6
file content (42 lines) | stat: -rwxr-xr-x 1,099 bytes parent folder | download | duplicates (2)
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
41
42
#!/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
}

if $0 == __FILE__
  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
end