Class: Lutaml::Cli::Uml::ServeCommand

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

Overview

ServeCommand starts interactive web UI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ServeCommand

Returns a new instance of ServeCommand.



11
12
13
# File 'lib/lutaml/cli/uml/serve_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/serve_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/serve_command.rb', line 15

def self.add_options_to(thor_class, _method_name)
  thor_class.long_desc <<-DESC
  Start a web server with an interactive UI for browsing the model.

  Uses the modern single-page application with JSON API and lunr.js search.

  Examples:
    lutaml uml serve model.lur
    lutaml uml serve model.lur --port 8080
  DESC

  thor_class.option :port, aliases: "-p", type: :numeric, default: 3000,
                           desc: "Port to listen on"
  thor_class.option :host, aliases: "-h",
                           type: :string, default: "localhost",
                           desc: "Host to bind to"
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
# File 'lib/lutaml/cli/uml/serve_command.rb', line 33

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

  puts OutputFormatter.colorize("\n=== Starting Web UI Server ===\n",
                                :cyan)
  puts "Loading repository from: #{lur_path}"
  puts "Server will be available at: " \
       "http://#{options[:host]}:#{options[:port]}"
  puts "\nPress Ctrl+C to stop the server\n\n"

  Lutaml::Xmi::WebUi::App.serve(lur_path,
                                port: options[:port],
                                host: options[:host])
rescue Interrupt
  puts "\n\n#{OutputFormatter.colorize('Server stopped', :yellow)}"
rescue StandardError => e
  puts OutputFormatter.error("Server error: #{e.message}")
  puts e.backtrace.first(5).join("\n") if options[:verbose]
  raise Thor::Error, "Server error: #{e.message}"
end