Class: Metanorma::Cli::Commands::Diff
- Inherits:
-
Object
- Object
- Metanorma::Cli::Commands::Diff
- Defined in:
- lib/metanorma/cli/commands/diff.rb
Overview
Semantic diff of two Metanorma XML documents, with lutaml/canon as the diff engine (metanorma-cli#442, iso-10303 drift-tracking). Returns an exit status instead of exiting, so in-process callers (and specs) stay alive; the Thor command decides the process exit.
Constant Summary collapse
- EXIT_EQUIVALENT =
0- EXIT_DIFFERENT =
1- EXIT_ERROR =
2- FORMAT_BY_EXT =
the canon LIBRARY does not auto-detect input format (its CLI does, from extensions) — detect here, overridable via --input-format
{ ".xml" => :xml, ".html" => :html, ".htm" => :html, ".json" => :json, ".yaml" => :yaml, ".yml" => :yaml }.freeze
Instance Method Summary collapse
-
#initialize(file1, file2, options = {}) ⇒ Diff
constructor
A new instance of Diff.
-
#run(out = $stdout) ⇒ Integer
Exit status (0 equivalent / 1 different / 2 error); output goes to the given IO (default $stdout).
Constructor Details
#initialize(file1, file2, options = {}) ⇒ Diff
Returns a new instance of Diff.
24 25 26 27 28 |
# File 'lib/metanorma/cli/commands/diff.rb', line 24 def initialize(file1, file2, = {}) @file1 = file1 @file2 = file2 @options = end |
Instance Method Details
#run(out = $stdout) ⇒ Integer
Returns exit status (0 equivalent / 1 different / 2 error); output goes to the given IO (default $stdout).
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/metanorma/cli/commands/diff.rb', line 32 def run(out = $stdout) return EXIT_ERROR unless files_exist? require "canon" format = input_format return reject_format unless format configure_canon report(compare_documents(format), out) rescue StandardError => e warn "metanorma diff: #{e.class}: #{e.}" EXIT_ERROR end |