Class: Lutaml::Cli::Uml::BuildCommand

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

Overview

BuildCommand builds LUR packages from XMI or QEA files

Constant Summary collapse

METADATA_OPTIONAL_FIELDS =
%i[
  publisher license description homepage keywords authors maintainers
].freeze
COLLECTION_NAMES =
{
  "object" => "classes",
  "package" => "packages",
  "attribute" => "attributes",
  "connector" => "associations",
  "diagram" => "diagrams",
  "operation" => "operations",
  "operationparams" => "operation parameters",
  "diagramobjects" => "diagram objects",
  "diagramlinks" => "diagram links",
  "objectconstraint" => "constraints",
  "taggedvalue" => "tagged values",
  "objectproperties" => "properties",
  "attributetag" => "attribute tags",
  "xref" => "cross-references",
  "stereotypes" => "stereotypes",
  "datatypes" => "data types",
  "constrainttypes" => "constraint types",
  "connectortypes" => "connector types",
  "diagramtypes" => "diagram types",
  "objecttypes" => "object types",
  "statustypes" => "status types",
  "complexitytypes" => "complexity types",
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BuildCommand

Returns a new instance of BuildCommand.



39
40
41
# File 'lib/lutaml/cli/uml/build_command.rb', line 39

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



37
38
39
# File 'lib/lutaml/cli/uml/build_command.rb', line 37

def options
  @options
end

Class Method Details

.add_options_to(thor_class, _method_name) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



43
44
45
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
# File 'lib/lutaml/cli/uml/build_command.rb', line 43

def self.add_options_to(thor_class, _method_name) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  thor_class.long_desc <<-DESC
  Build a LUR (LutaML UML Repository) package from an XMI or QEA source file.

  The file format is auto-detected from the extension:
  - .xmi files are parsed as XMI
  - .qea files are parsed as QEA (Enterprise Architect)

  If --output is not specified, the output filename will be the input filename
  with the extension changed to .lur

  Examples:
    lutaml uml build model.xmi -o model.lur

    lutaml uml build project.qea -o project.lur --validate

    lutaml uml build model.qea     # Creates model.lur

    # With metadata
    lutaml uml build model.xmi --name "Urban Model" --version "2.0" \
      --publisher "City Planning" --license "CC-BY-4.0"

    # Load metadata from file
    lutaml uml build model.xmi --metadata-file package-info.yaml
  DESC

  thor_class.option :output, aliases: "-o", type: :string,
                             desc: "Output .lur file path " \
                                   "(default: input file with .lur " \
                                   "extension)"

  thor_class.option :name, type: :string, desc: "Package name"
  thor_class.option :version, type: :string, default: "1.0",
                              desc: "Package version"
  thor_class.option :publisher, type: :string,
                                desc: "Publisher or organization name"
  thor_class.option :license, type: :string,
                              desc: "License identifier " \
                                    "(e.g., MIT, CC-BY-4.0)"
  thor_class.option :description, type: :string,
                                  desc: "Package description"
  thor_class.option :homepage, type: :string, desc: "Homepage URL"
  thor_class.option :keywords, type: :string,
                               desc: "Comma-separated keywords"
  thor_class.option :authors, type: :array,
                              desc: "Author names (can be specified " \
                                    "multiple times)"
  thor_class.option :maintainers, type: :string,
                                  desc: "Maintainer contact information"
  thor_class.option :metadata_file, type: :string,
                                    desc: "Load metadata from YAML file"

  thor_class.option :format, type: :string, default: "yaml",
                             desc: "Serialization format (yaml)"
  thor_class.option :validate, type: :boolean, default: true,
                               desc: "Validate before building"
  thor_class.option :strict, type: :boolean, default: false,
                             desc: "Fail build on validation errors"
  thor_class.option :show_warnings, type: :boolean, default: true,
                                    desc: "Show validation warnings"
  thor_class.option :limit_errors, type: :numeric, default: nil,
                                   desc: "Limit validation errors " \
                                         "shown (default: all " \
                                         "if <100, else 50)"
  thor_class.option :validation_format, type: :string, default: "text",
                                        desc: "Validation output " \
                                              "format (text|json)"
  thor_class.option :quick, type: :boolean, default: false,
                            desc: "Quick mode: build + validate + stats"
  thor_class.option :verbose, type: :boolean, default: false,
                              desc: "Show detailed type resolution " \
                                    "for each attribute"
end

Instance Method Details

#run(model_path) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/lutaml/cli/uml/build_command.rb', line 117

def run(model_path) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  validate_input_file(model_path)

  output_path = resolve_output_path(model_path)
  is_qea = model_path.end_with?(".qea")

  repo, qea_result = parse_source(model_path, is_qea)

  if qea_result && options[:validate]
    display_qea_validation_result(qea_result)
    fail_build!("validation errors") if options[:strict] && qea_result.has_errors?
  end

  validate_repository(repo) if should_validate?(is_qea)

   = 
  export_package(repo, output_path, )
  display_build_summary(, repo, output_path)
rescue StandardError => e
  OutputFormatter.progress_done(success: false)
  puts OutputFormatter.error("Failed to build package: #{e.message}")
  puts e.backtrace.first(5).join("\n") if ENV["DEBUG"]
  raise Thor::Error, "Failed to build package: #{e.message}"
end