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.
-
#bookmarks_cmd ⇒ Object
readonly
Returns the value of attribute bookmarks_cmd.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#current_path ⇒ Object
Returns the value of attribute current_path.
-
#export ⇒ Object
readonly
Returns the value of attribute export.
-
#help ⇒ Object
readonly
Returns the value of attribute help.
-
#last_results ⇒ Object
Returns the value of attribute last_results.
-
#navigation ⇒ Object
readonly
Returns the value of attribute navigation.
-
#path_history ⇒ Object
readonly
Returns the value of attribute path_history.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#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.
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
#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 |
#bookmarks_cmd ⇒ Object (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 |
#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
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 |
#export ⇒ Object (readonly)
Returns the value of attribute export.
20 21 22 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 20 def export @export end |
#help ⇒ Object (readonly)
Returns the value of attribute help.
20 21 22 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 20 def help @help end |
#last_results ⇒ Object
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 |
#navigation ⇒ Object (readonly)
Returns the value of attribute navigation.
20 21 22 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 20 def @navigation 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 |
#query ⇒ Object (readonly)
Returns the value of attribute query.
20 21 22 |
# File 'lib/lutaml/cli/interactive_shell.rb', line 20 def query @query 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
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.}") puts e.backtrace.first(3).join("\n") if ENV["DEBUG"] end end save_history puts "\nGoodbye!" end |