Class: Lutaml::Cli::Uml::ValidateCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/cli/uml/validate_command.rb

Overview

ValidateCommand validates LUR packages or QEA files

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ValidateCommand

Returns a new instance of ValidateCommand.



11
12
13
# File 'lib/lutaml/cli/uml/validate_command.rb', line 11

def initialize(options = {})
  @options = options.transform_keys(&:to_sym)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/lutaml/cli/uml/validate_command.rb', line 9

def options
  @options
end

Class Method Details

.add_options_to(thor_class, _method_name) ⇒ Object

rubocop:disable Metrics/MethodLength



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
# File 'lib/lutaml/cli/uml/validate_command.rb', line 15

def self.add_options_to(thor_class, _method_name) # rubocop:disable Metrics/MethodLength
  thor_class.long_desc <<-DESC
  Validate a LUR package or QEA file for consistency and completeness.

  Auto-detects file type:
  - .lur files: Validate LUR package structure
  - .qea files: Validate QEA file structure and integrity

  LUR validation checks:
  - Dangling references
  - Missing types
  - External dependencies
  - Structural integrity

  QEA validation checks:
  - Package structure validation
  - Class and attribute validation
  - Association endpoint validation
  - Referential integrity
  - Orphaned elements
  - Circular references

  Examples:
    lutaml uml validate model.lur
    lutaml uml validate model.qea
    lutaml uml validate model.qea --format json -o report.json
  DESC

  thor_class.option :format, type: :string, default: "text",
                             desc: "Output format (text|json)"
  thor_class.option :output, aliases: "-o", type: :string,
                             desc: "Save report to file"
  thor_class.option :strict, type: :boolean, default: false,
                             desc: "Exit with error if validation fails"
  thor_class.option :show_warnings, type: :boolean, default: true,
                                    desc: "Show warnings in output"
  thor_class.option :verbose, type: :boolean, default: false,
                              desc: "Show detailed validation messages"
end

Instance Method Details

#run(file_path) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



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
# File 'lib/lutaml/cli/uml/validate_command.rb', line 55

def run(file_path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  unless File.exist?(file_path)
    puts OutputFormatter.error("File not found: #{file_path}")
    raise Thor::Error, "File not found: #{file_path}"
  end

  # Auto-detect file type
  if file_path.end_with?(".qea")
    validate_qea_file(file_path)
  elsif file_path.end_with?(".lur")
    validate_lur_file(file_path)
  else
    puts OutputFormatter.error(
      "Unsupported file type. Please provide a .qea or .lur file.",
    )
    raise Thor::Error,
          "Unsupported file type. Please provide a .qea or .lur file."
  end
rescue Thor::Error
  raise
rescue StandardError => e
  OutputFormatter.progress_done(success: false)
  puts OutputFormatter.error("Validation failed: #{e.message}")
  puts e.backtrace.first(5).join("\n") if ENV["DEBUG"]
  raise Thor::Error, "Validation failed: #{e.message}"
end