Class: Lutaml::Cli::InteractiveShell

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

Overview

InteractiveShell provides a full-featured REPL for exploring UML repositories

Features:

  • Readline integration with history

  • Tab completion for commands and paths

  • Colorized prompts and output

  • Navigation commands (cd, pwd, ls, tree, up, root, back)

  • Query commands (find, show, search)

  • Bookmark management

  • Results management

  • Command history persistence

Constant Summary collapse

HISTORY_FILE =
File.expand_path("~/.lutaml-xmi-history")
MAX_HISTORY =
1000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lur_path_or_repo, config: nil) ⇒ InteractiveShell

Initialize the interactive shell

repository

Parameters:

  • lur_path_or_repo (String, UmlRepository)

    Path to LUR file or

  • config (Hash) (defaults to: nil)

    Configuration options

Options Hash (config:):

  • :color (Boolean)

    Enable colored output

  • :icons (Boolean)

    Enable icons in output



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
# File 'lib/lutaml/cli/interactive_shell.rb', line 36

def initialize(lur_path_or_repo, config: nil) # rubocop:disable Metrics/MethodLength
  @config = {
    color: true,
    icons: true,
    show_counts: true,
    page_size: 50,
  }.merge(config || {})

  # Load repository
  if lur_path_or_repo.is_a?(String)
    OutputFormatter.progress("Loading repository")
    @repository = Lutaml::UmlRepository::Repository.from_package(lur_path_or_repo)
    OutputFormatter.progress_done
  else
    @repository = lur_path_or_repo
  end

  # Initialize state
  @current_path = "ModelRoot"
  @bookmarks = {}
  @last_results = nil
  @path_history = ["ModelRoot"]
  @running = false

  setup_readline
  load_history
end

Instance Attribute Details

#bookmarksObject (readonly)

Returns the value of attribute bookmarks.



26
27
28
# File 'lib/lutaml/cli/interactive_shell.rb', line 26

def bookmarks
  @bookmarks
end

#configObject (readonly)

Returns the value of attribute config.



26
27
28
# File 'lib/lutaml/cli/interactive_shell.rb', line 26

def config
  @config
end

#current_pathObject (readonly)

Returns the value of attribute current_path.



26
27
28
# File 'lib/lutaml/cli/interactive_shell.rb', line 26

def current_path
  @current_path
end

#last_resultsObject (readonly)

Returns the value of attribute last_results.



26
27
28
# File 'lib/lutaml/cli/interactive_shell.rb', line 26

def last_results
  @last_results
end

#path_historyObject (readonly)

Returns the value of attribute path_history.



26
27
28
# File 'lib/lutaml/cli/interactive_shell.rb', line 26

def path_history
  @path_history
end

#repositoryObject (readonly)

Returns the value of attribute repository.



26
27
28
# File 'lib/lutaml/cli/interactive_shell.rb', line 26

def repository
  @repository
end

Instance Method Details

#startvoid

This method returns an undefined value.

Start the REPL loop



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
# File 'lib/lutaml/cli/interactive_shell.rb', line 67

def start # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  @running = true
  display_welcome

  while @running
    begin
      input = Readline.readline(prompt, true)

      # Exit on Ctrl+D or nil input
      break if input.nil?

      # Skip empty lines
      next if input.strip.empty?

      # Don't save duplicates in history
      if Readline::HISTORY.length > 1 &&
          Readline::HISTORY[-2] == input
        Readline::HISTORY.pop
      end

      execute_command(input.strip)
    rescue Interrupt
      puts "\nUse 'exit' or 'quit' to exit the shell"
    rescue StandardError => e
      puts OutputFormatter.error("Error: #{e.message}")
      puts e.backtrace.first(3).join("\n") if ENV["DEBUG"]
    end
  end

  save_history
  puts "\nGoodbye!"
end