Class: Suma::Cli::Compare

Inherits:
Thor
  • Object
show all
Defined in:
lib/suma/cli/compare.rb

Overview

Command to compare EXPRESS schemas using eengine

Instance Method Summary collapse

Instance Method Details

#compare(trial_schema, reference_schema) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/suma/cli/compare.rb', line 46

def compare(trial_schema, reference_schema)
  # Validate schema files exist
  unless File.exist?(trial_schema)
    say "Error: Trial schema not found: #{trial_schema}", :red
    exit 1
  end

  unless File.exist?(reference_schema)
    say "Error: Reference schema not found: #{reference_schema}", :red
    exit 1
  end

  # Check eengine availability
  unless Eengine::Wrapper.available?
    say "Error: eengine not found in PATH", :red
    say "Install eengine following instructions at:"
    say "  macOS: https://github.com/expresslang/homebrew-eengine"
    say "  Linux: https://github.com/expresslang/eengine-releases"
    exit 1
  end

  # Auto-detect repo roots
  trial_stepmod = options[:trial_stepmod] ||
    detect_repo_root(trial_schema)
  reference_stepmod = options[:reference_stepmod] ||
    detect_repo_root(reference_schema)

  if options[:verbose]
    say "Using eengine version: #{Eengine::Wrapper.version}", :green
    say "Trial repo root: #{trial_stepmod}", :cyan
    say "Reference repo root: #{reference_stepmod}", :cyan
  end

  # Create a temporary directory for eengine output
  require "tmpdir"
  out_dir = nil
  out_dir = Dir.mktmpdir("eengine-compare-")

  # Run comparison
  result = Eengine::Wrapper.compare(
    trial_schema,
    reference_schema,
    mode: options[:mode],
    trial_stepmod: trial_stepmod,
    reference_stepmod: reference_stepmod,
    out_dir: out_dir,
  )

  unless result[:has_changes]
    say "No changes detected between schemas", :yellow
    # Clean up temp directory
    FileUtils.rm_rf(out_dir) if out_dir && File.directory?(out_dir)
    return
  end

  unless result[:xml_path]
    say "Error: XML output not found", :red
    exit 1
  end

  if options[:verbose]
    say "Comparison XML generated: #{result[:xml_path]}", :green
  end

  # Convert to Change YAML
  convert_to_change_yaml(result[:xml_path], trial_schema, out_dir)
rescue Eengine::EengineError => e
  # Clean up temp directory
  FileUtils.rm_rf(out_dir) if out_dir && File.directory?(out_dir)
  say "Error: #{e.message}", :red
  say e.stderr if e.respond_to?(:stderr) && options[:verbose]
  exit 1
end