Class: Json::Schema::Diff::CLI
- Inherits:
-
Object
- Object
- Json::Schema::Diff::CLI
- Defined in:
- lib/json/schema/diff/cli.rb
Overview
Command-line interface for json-schema-diff
Provides a comprehensive CLI for comparing JSON files using JSON Schema guidance. Supports multiple output formats, validation options, and field filtering.
Class Method Summary collapse
-
.start(args) ⇒ void
Entry point for the CLI application.
Instance Method Summary collapse
-
#run(args) ⇒ void
Runs the CLI with the provided arguments.
Class Method Details
.start(args) ⇒ void
This method returns an undefined value.
Entry point for the CLI application
15 16 17 |
# File 'lib/json/schema/diff/cli.rb', line 15 def self.start(args) new.run(args) end |
Instance Method Details
#run(args) ⇒ void
This method returns an undefined value.
Runs the CLI with the provided arguments
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/json/schema/diff/cli.rb', line 24 def run(args) = (args) if args.length != 3 puts "Usage: json-schema-diff [OPTIONS] SCHEMA OLD_JSON NEW_JSON" puts "Try 'json-schema-diff --help' for more information." exit 1 end schema_file, old_file, new_file = args begin schema = SchemaParser.new(schema_file, validate_schema: [:validate]) comparer = Comparer.new(schema, [:ignore_fields] || []) old_json = JSON.parse(File.read(old_file)) new_json = JSON.parse(File.read(new_file)) # Validate JSON files against schema if requested if [:validate_json] schema.validate_json(old_json) schema.validate_json(new_json) end diff_result = comparer.compare(old_json, new_json) formatter = Formatter.new([:format], [:color]) puts formatter.format(diff_result) rescue JSON::ParserError => e puts "Error parsing JSON: #{e.}" exit 1 rescue Errno::ENOENT => e puts "File not found: #{e.}" exit 1 rescue Error => e puts "Error: #{e.}" exit 1 end end |