Class: Lutaml::Cli::Uml::InspectCommand

Inherits:
Object
  • Object
show all
Includes:
SharedHelpers
Defined in:
lib/lutaml/cli/uml/inspect_command.rb

Overview

InspectCommand shows detailed element information

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedHelpers

#load_repository, #normalize_path

Constructor Details

#initialize(options = {}) ⇒ InspectCommand

Returns a new instance of InspectCommand.



15
16
17
# File 'lib/lutaml/cli/uml/inspect_command.rb', line 15

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/lutaml/cli/uml/inspect_command.rb', line 13

def options
  @options
end

Class Method Details

.add_options_to(thor_class, _method_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lutaml/cli/uml/inspect_command.rb', line 19

def self.add_options_to(thor_class, _method_name)
  thor_class.long_desc <<-DESC
  Display detailed information about a specific element.

  Element format: type:identifier
  - package:ModelRoot::Core
  - class:ModelRoot::Core::Building
  - diagram:ClassDiagram1
  - attribute:ModelRoot::Core::Building::name

  Examples:
    lutaml uml inspect model.lur class:Building
    lutaml uml inspect model.lur package:ModelRoot::Core
    lutaml uml inspect model.lur diagram:Overview
  DESC

  thor_class.option :format, type: :string, default: "text",
                             desc: "Output format (text|yaml|json)"
  thor_class.option :include, type: :array,
                              desc: "Include sections (attributes, " \
                                    "associations, operations)"
  thor_class.option :lazy, type: :boolean, default: false,
                           desc: "Use lazy loading"
end

Instance Method Details

#run(lur_path, element_id) ⇒ Object

rubocop:disable Metrics/MethodLength



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lutaml/cli/uml/inspect_command.rb', line 44

def run(lur_path, element_id) # rubocop:disable Metrics/MethodLength
  repo = load_repository(lur_path, lazy: options[:lazy])
  identifier = ElementIdentifier.parse(element_id)

  element = find_element(repo, identifier)
  unless element
    puts OutputFormatter.error("Element not found: #{element_id}")
    raise Thor::Error, "Element not found: #{element_id}"
  end

  display_element_details(element, identifier, repo)
rescue Thor::Error
  raise
rescue ArgumentError => e
  raise Thor::Error, e.message
rescue StandardError => e
  raise Thor::Error, "Inspect command failed: #{e.message}"
end