Class: Lutaml::Cli::InteractiveShell
- Inherits:
-
Object
- Object
- Lutaml::Cli::InteractiveShell
- 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.("~/.lutaml-xmi-history")
- MAX_HISTORY =
1000
Instance Attribute Summary collapse
-
#bookmarks ⇒ Object
readonly
Returns the value of attribute bookmarks.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#current_path ⇒ Object
readonly
Returns the value of attribute current_path.
-
#last_results ⇒ Object
readonly
Returns the value of attribute last_results.
-
#path_history ⇒ Object
readonly
Returns the value of attribute path_history.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#initialize(lur_path_or_repo, config: nil) ⇒ InteractiveShell
constructor
A new instance of InteractiveShell.
- #start ⇒ Object
Constructor Details
#initialize(lur_path_or_repo, config: nil) ⇒ InteractiveShell
Returns a new instance of InteractiveShell.
23 24 25 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 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 23 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
#bookmarks ⇒ Object (readonly)
Returns the value of attribute bookmarks.
20 21 22 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 20 def bookmarks @bookmarks end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
20 21 22 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 20 def config @config end |
#current_path ⇒ Object (readonly)
Returns the value of attribute current_path.
20 21 22 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 20 def current_path @current_path end |
#last_results ⇒ Object (readonly)
Returns the value of attribute last_results.
20 21 22 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 20 def last_results @last_results end |
#path_history ⇒ Object (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 |
#repository ⇒ Object (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
#start ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 55 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.}") puts e.backtrace.first(3).join("\n") if ENV["DEBUG"] end end save_history puts "\nGoodbye!" end |