Class: Lutaml::Cli::Uml::BuildCommand
- Inherits:
-
Object
- Object
- Lutaml::Cli::Uml::BuildCommand
- Defined in:
- lib/lutaml/cli/uml/build_command.rb
Overview
BuildCommand builds LUR packages from XMI or QEA files
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.add_options_to(thor_class, _method_name) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BuildCommand
constructor
A new instance of BuildCommand.
-
#run(model_path) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
Constructor Details
#initialize(options = {}) ⇒ BuildCommand
Returns a new instance of BuildCommand.
14 15 16 |
# File 'lib/lutaml/cli/uml/build_command.rb', line 14 def initialize( = {}) @options = .transform_keys(&:to_sym) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/lutaml/cli/uml/build_command.rb', line 12 def @options end |
Class Method Details
.add_options_to(thor_class, _method_name) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
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 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 |
# File 'lib/lutaml/cli/uml/build_command.rb', line 18 def self.(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)" # Package metadata options 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" # Build options thor_class.option :format, type: :string, default: "marshal", desc: "Serialization format (marshal|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/MethodLength,Metrics/PerceivedComplexity
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/lutaml/cli/uml/build_command.rb', line 94 def run(model_path) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity unless File.exist?(model_path) puts OutputFormatter.error("Model file not found: #{model_path}") raise Thor::Error, "Model file not found: #{model_path}" end # Set default output path if not provided output_path = [:output] || model_path.sub(/\.(xmi|qea)$/i, ".lur") # Detect file type is_qea = model_path.end_with?(".qea") file_type = is_qea ? "QEA" : "XMI" # Parse with validation for QEA files repo, qea_validation_result = if is_qea require_relative "../../qea" parse_qea_with_validation(model_path) else OutputFormatter.progress( "Parsing #{file_type} file", ) r = Lutaml::UmlRepository::Repository .from_xmi(model_path) OutputFormatter.progress_done [r, nil] end # Display QEA validation results if available if qea_validation_result && [:validate] display_qea_validation_result(qea_validation_result) if [:strict] && qea_validation_result.has_errors? puts "" puts OutputFormatter.error( "Build failed due to validation errors", ) raise Thor::Error, "Build failed due to validation errors" end end # Validate repository if requested # (XMI files or additional validation) # Strict mode forces validation even if --no-validate is passed if ([:validate] || [:strict]) && !is_qea OutputFormatter.progress("Validating repository") result = repo.validate(verbose: [:verbose]) OutputFormatter.progress_done # Display verbose validation if requested if [:verbose] && result.respond_to?(:validation_details) display_verbose_validation(result.validation_details) end unless result.valid? handle_validation_result(result) # Display unique unresolved types if present if result.respond_to?(:external_references) && result.external_references.any? display_unresolved_types(result.external_references) end if [:strict] && result.errors.any? raise Thor::Error, "Build failed due to validation errors" end end end # Build metadata from options = # Export to package with metadata = { serialization_format: ( [:format] || ["format"] || "marshal" ).to_sym, metadata: , } OutputFormatter.progress("Exporting to LUR package") repo.export_to_package(output_path, ) OutputFormatter.progress_done # Show success with statistics stats = repo.statistics puts "" puts OutputFormatter .success("Package built successfully: #{output_path}") puts "" puts "Package Metadata:" puts " Name: #{.name}" puts " Version: #{.version}" puts " Publisher: #{.publisher}" if .publisher puts " License: #{.license}" if .license puts "" puts "Package Contents:" puts " Packages: #{stats[:total_packages]}" puts " Classes: #{stats[:total_classes]}" puts " Data Types: #{stats[:total_data_types]}" puts " Enumerations: #{stats[:total_enums]}" puts " Diagrams: #{stats[:total_diagrams]}" rescue StandardError => e OutputFormatter.progress_done(success: false) puts OutputFormatter.error("Failed to build package: #{e.}") puts e.backtrace.first(5).join("\n") if ENV["DEBUG"] raise Thor::Error, "Failed to build package: #{e.}" end |