Class: Lutaml::Cli::InteractiveShell

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/cli/interactive_shell.rb,
lib/lutaml/cli/interactive_shell/command_base.rb,
lib/lutaml/cli/interactive_shell/help_display.rb,
lib/lutaml/cli/interactive_shell/export_handler.rb,
lib/lutaml/cli/interactive_shell/query_commands.rb,
lib/lutaml/cli/interactive_shell/bookmark_commands.rb,
lib/lutaml/cli/interactive_shell/navigation_commands.rb

Defined Under Namespace

Classes: BookmarkCommands, CommandBase, ExportHandler, HelpDisplay, NavigationCommands, QueryCommands

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

Returns a new instance of InteractiveShell.



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

def initialize(lur_path_or_repo, config: nil)
  @config = {
    color: true,
    icons: true,
    show_counts: true,
    page_size: 50,
  }.merge(config || {})

  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

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

  @navigation = NavigationCommands.new(self)
  @query = QueryCommands.new(self)
  @bookmarks_cmd = BookmarkCommands.new(self)
  @export = ExportHandler.new(self)
  @help = HelpDisplay.new(self)

  setup_readline
  load_history
end

Instance Attribute Details

#bookmarksObject (readonly)

Returns the value of attribute bookmarks.



20
21
22
# File 'lib/lutaml/cli/interactive_shell.rb', line 20

def bookmarks
  @bookmarks
end

#bookmarks_cmdObject (readonly)

Returns the value of attribute bookmarks_cmd.



20
21
22
# File 'lib/lutaml/cli/interactive_shell.rb', line 20

def bookmarks_cmd
  @bookmarks_cmd
end

#configObject (readonly)

Returns the value of attribute config.



20
21
22
# File 'lib/lutaml/cli/interactive_shell.rb', line 20

def config
  @config
end

#current_pathObject

Returns the value of attribute current_path.



24
25
26
# File 'lib/lutaml/cli/interactive_shell.rb', line 24

def current_path
  @current_path
end

#exportObject (readonly)

Returns the value of attribute export.



20
21
22
# File 'lib/lutaml/cli/interactive_shell.rb', line 20

def export
  @export
end

#helpObject (readonly)

Returns the value of attribute help.



20
21
22
# File 'lib/lutaml/cli/interactive_shell.rb', line 20

def help
  @help
end

#last_resultsObject

Returns the value of attribute last_results.



24
25
26
# File 'lib/lutaml/cli/interactive_shell.rb', line 24

def last_results
  @last_results
end

Returns the value of attribute navigation.



20
21
22
# File 'lib/lutaml/cli/interactive_shell.rb', line 20

def navigation
  @navigation
end

#path_historyObject (readonly)

Returns the value of attribute path_history.



20
21
22
# File 'lib/lutaml/cli/interactive_shell.rb', line 20

def path_history
  @path_history
end

#queryObject (readonly)

Returns the value of attribute query.



20
21
22
# File 'lib/lutaml/cli/interactive_shell.rb', line 20

def query
  @query
end

#repositoryObject (readonly)

Returns the value of attribute repository.



20
21
22
# File 'lib/lutaml/cli/interactive_shell.rb', line 20

def repository
  @repository
end

Instance Method Details

#startObject



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

def start
  @running = true
  @help.display_welcome

  while @running
    begin
      input = Readline.readline(prompt, true)
      break if input.nil?
      next if input.strip.empty?

      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