Class: Expressir::Commands::ChangesValidate
- Defined in:
- lib/expressir/commands/changes_validate.rb
Overview
Command to validate and normalize EXPRESS Changes YAML files
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#exit_with_error, #initialize, #say
Constructor Details
This class inherits a constructor from Expressir::Commands::Base
Instance Method Details
#run(path) ⇒ Object
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/expressir/commands/changes_validate.rb', line 9 def run(path) require "expressir/changes" # Check if file exists unless File.exist?(path) exit_with_error("File not found: #{path}") end # Validate --in-place requires --normalize if [:in_place] && ![:normalize] exit_with_error("--in-place requires --normalize flag") end # Validate --in-place and --output are mutually exclusive if [:in_place] && [:output] exit_with_error("Cannot use both --in-place and --output") end begin # Load and validate the file say "Validating #{path}..." if [:verbose] schema_change = Expressir::Changes::SchemaChange.from_file(path) say "✓ File is valid" if [:verbose] say " Schema: #{schema_change.schema}" if [:verbose] say " Versions: #{schema_change.versions.length}" if [:verbose] # Normalize if requested if [:normalize] say "Normalizing through round-trip serialization..." if [:verbose] output_path = if [:in_place] path elsif [:output] [:output] else # Output to stdout nil end if output_path schema_change.to_file(output_path) say "✓ Normalized file written to: #{output_path}" else # Output to stdout puts schema_change.to_yaml end else say "✓ File is valid" end rescue Psych::SyntaxError => e exit_with_error("Invalid YAML syntax: #{e.}") rescue StandardError => e exit_with_error("Validation failed: #{e.}") end end |