Class: Lutaml::Xsd::Commands::ValidateCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/lutaml/xsd/commands/validate_command.rb

Overview

CLI command for XML instance validation

Validates XML files against XSD schemas with support for:

  • Single file validation

  • Multiple file validation (glob patterns)

  • Various output formats (text, json, yaml)

  • Exit codes based on validation result

Instance Attribute Summary collapse

Attributes inherited from BaseCommand

#options

Instance Method Summary collapse

Constructor Details

#initialize(xml_files, schema_source, options = {}) ⇒ ValidateCommand

Initialize validate command

Parameters:

  • xml_files (Array<String>)

    XML file paths or glob patterns

  • schema_source (String)

    Schema package path or repository

  • options (Hash) (defaults to: {})

    Command options



24
25
26
27
28
# File 'lib/lutaml/xsd/commands/validate_command.rb', line 24

def initialize(xml_files, schema_source, options = {})
  super(options)
  @xml_files = Array(xml_files)
  @schema_source = schema_source
end

Instance Attribute Details

#schema_sourceObject (readonly)

Returns the value of attribute schema_source.



17
18
19
# File 'lib/lutaml/xsd/commands/validate_command.rb', line 17

def schema_source
  @schema_source
end

#xml_filesObject (readonly)

Returns the value of attribute xml_files.



17
18
19
# File 'lib/lutaml/xsd/commands/validate_command.rb', line 17

def xml_files
  @xml_files
end

Instance Method Details

#runvoid

This method returns an undefined value.

Run validation command



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lutaml/xsd/commands/validate_command.rb', line 33

def run
  validate_inputs
  files = expand_file_patterns

  if files.empty?
    error "No XML files found matching the specified patterns"
    exit 1
  end

  validator = create_validator
  results = validate_files(files, validator)

  output_results(results)
  exit_with_status(results)
rescue StandardError => e
  error "Validation failed: #{e.message}"
  verbose_output e.backtrace.join("\n") if verbose?
  exit 1
end