Class: Lutaml::Cli::Uml::ExportCommand

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

Overview

ExportCommand exports to structured formats

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ExportCommand

Returns a new instance of ExportCommand.



11
12
13
# File 'lib/lutaml/cli/uml/export_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/export_command.rb', line 9

def options
  @options
end

Class Method Details

.add_options_to(thor_class, _method_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lutaml/cli/uml/export_command.rb', line 15

def self.add_options_to(thor_class, _method_name)
  thor_class.long_desc <<-DESC
  Export repository data to various formats.

  Examples:
    lutaml uml export model.lur --format json -o model.json
    lutaml uml export model.lur --format markdown -o docs/
  DESC

  thor_class.option :format, type: :string, required: true,
                             desc: "Export format (json|markdown)"
  thor_class.option :output, aliases: "-o", required: true,
                             desc: "Output path"
  thor_class.option :package, type: :string, desc: "Filter by package"
  thor_class.option :recursive, type: :boolean, default: true,
                                desc: "Include nested packages"
end

Instance Method Details

#run(lur_path) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



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

def run(lur_path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  repo = load_repository(lur_path)

  exporter_class = case options[:format].downcase
                   when "json"
                     Lutaml::UmlRepository::Exporters::JsonExporter
                   when "markdown"
                     Lutaml::UmlRepository::Exporters::MarkdownExporter
                   else
                     puts OutputFormatter.error(
                       "Unknown format: #{options[:format]}",
                     )
                     raise Thor::Error,
                           "Unknown format: #{options[:format]}"
                   end

  exporter = exporter_class.new(repo)

  OutputFormatter.progress("Exporting to #{options[:format]}")
  exporter.export(options[:output],
                  options.to_h.transform_keys(&:to_sym))
  OutputFormatter.progress_done

  puts OutputFormatter.success("Exported to #{options[:output]}")
rescue StandardError => e
  OutputFormatter.progress_done(success: false)
  puts OutputFormatter.error("Export failed: #{e.message}")
  raise Thor::Error, "Export failed: #{e.message}"
end