Class: LanguageOperator::CLI::Commands::Ui
- Inherits:
-
BaseCommand
- Object
- Thor
- BaseCommand
- LanguageOperator::CLI::Commands::Ui
- Defined in:
- lib/language_operator/cli/commands/ui.rb
Overview
UI command to open the Language Operator dashboard in browser
Constant Summary collapse
- DEFAULT_PORT =
8080- DEFAULT_SERVICE_NAME =
'language-operator-dashboard'- DEFAULT_SERVICE_PORT =
3000
Instance Method Summary collapse
Methods included from Helpers::UxHelper
#box, #highlight_ruby_code, #logo, #pastel, #prompt, #spinner, #table
Instance Method Details
#ui ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 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 81 82 83 84 |
# File 'lib/language_operator/cli/commands/ui.rb', line 44 def ui handle_command_error('open dashboard') do logo(title: 'open dashboard') # Check if operator is installed and get service info validate_operator_installation port = [:port] service_name = [:service] service_port = [:service_port] # Start port forward in background port_forward_pid = start_port_forward(service_name, service_port, port) # Wait a moment for port forward to establish sleep 2 # Open browser unless --no-open open_browser("http://localhost:#{port}") unless [:no_open] puts puts 'If your browser was not opened automatically, your dashboard is at:' puts pastel.white.bold("http://localhost:#{port}") puts puts 'Press Ctrl+C to stop the port forward and exit' # Handle graceful shutdown trap('INT') do puts "\nStopping port forward..." stop_port_forward(port_forward_pid) puts 'Dashboard closed.' exit 0 end # Keep the process running loop do sleep 1 end end end |