Class: Hyraft::Server::Launcher
- Inherits:
-
Object
- Object
- Hyraft::Server::Launcher
- Defined in:
- lib/hyraft/server/launcher.rb
Overview
Main server launcher for Hyraft framework
Handles starting web and API servers with support for multiple Ruby server backends (Puma, Thin, Falcon, Iodine)
Usage Examples
hyr s thin # Start web server with Thin
hyr s thin --api # Start API server with Thin
hyraft-server puma -p 1025 # Start on custom port
hyraft-server falcon --http2 # Start with HTTP/2
Constant Summary collapse
- COLORS =
ANSI color codes for terminal output
{ lime: "\033[92m", yellow: "\033[93m", light_red: "\033[91m", green: "\e[32m", red: "\e[31m", reset: "\033[0m" }
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Launcher
constructor
Initialize a new launcher instance.
-
#show_usage ⇒ void
Display comprehensive usage information.
-
#start(cmd, args) ⇒ void
Start the server with given command and arguments.
Constructor Details
#initialize(options = {}) ⇒ Launcher
Initialize a new launcher instance
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hyraft/server/launcher.rb', line 55 def initialize( = {}) @options = { server: nil, host: "localhost", port: 1025, port_api: 1126, rack_socket: "setup/server/web-server.ru", rack_socket_api: "setup/server/api-server.ru", http2: false, http3: false, api: false }.merge() end |
Instance Method Details
#show_usage ⇒ void
This method returns an undefined value.
Display comprehensive usage information
Shows available commands, options, and examples for the Hyraft server. Includes colorized output when not in test environment.
Command Variants
Alias: (or Shortcut) hyr s [server-name] Start web server hyr s [server-name] --api Start API server directly hyr s-v Show version hyr s-h Show this help
Medium Form:
hyr-serve [server-name] Start web server
hyr-serve [server-name] --api Start API server directly
hyr-serve s-v Show version
hyr-serve s-h Show this help
Full Command:
hyraft-server [server-name] [options] Start web server
hyraft-server [server-name] --api [options] Start API server directly
hyraft-server server-version Show version
hyraft-server server-help Show this help
Examples
hyr s thin # Start web server with Thin
hyr-serve thin # Start web server with Thin
hyraft-server thin # Start web server with Thin
hyraft-server thin --api # Start API server with Thin
hyraft-server puma -p 1025 # Start web server on port 1025
hyraft-server puma --port-api 1126 # Start API server on port 1126
hyraft-server falcon --http2 # Start with HTTP/2 (Falcon)
hyraft-server falcon --http3 # Start with HTTP/3 (Falcon)
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/hyraft/server/launcher.rb', line 167 def show_usage title_color = colorize? ? COLORS[:lime] : "" header_color = colorize? ? COLORS[:yellow] : "" reset_color = colorize? ? COLORS[:reset] : "" puts "#{title_color}Hyraft Server #{Hyraft::Server::VERSION}#{reset_color}" puts "High-performance web server with hexagonal architecture" puts "" puts "#{header_color}Usage:#{reset_color}" puts " hyraft-server [server-name] [options]" puts "" puts "#{header_color}Hotkey:#{reset_color}" puts " hyr s [server-name] Start web server (legacy)" puts " hyr s [server-name] --api Start API server directly" puts " hyr s-v Show version" puts " hyr s-h Show this help" puts "" puts "#{header_color}Shortkey:#{reset_color}" puts " hyr-serve [server-name] Start web server (legacy)" puts " hyr-serve [server-name] --api Start API server directly" puts " hyr-serve s-v Show version" puts " hyr-serve s-h Show this help" puts "" puts "#{header_color}Standard Key:#{reset_color}" puts " hyraft-server [server-name] [options] Start web server (legacy)" puts " hyraft-server [server-name] --api [options] Start API server directly" puts " hyraft-server server-version Show version" puts " hyraft-server server-help Show this help" puts "" puts "#{header_color}Servers:#{reset_color} puma, thin, falcon, iodine" puts "" puts "#{header_color}Options:#{reset_color}" puts " -s, --server SERVER Server (puma, thin, falcon, iodine)" puts " -b, --bind HOST Host (default: localhost)" puts " -p, --port PORT Port (default: 1025)" puts " --port-api PORT API Port (default: 1126)" puts " -c, --config FILE Rack config file" puts " --config-api FILE API Rack config file" puts " --api Enable API server" puts " --http2 Enable HTTP/2 (Falcon only)" puts " --http3 Enable HTTP/3 (Falcon only)" puts "" puts "#{header_color}Examples:#{reset_color}" example_color = colorize? ? COLORS[:lime] : "" puts "#{example_color} hyr s thin #{reset_color}# Start web server with Thin - Hotkey" puts "#{example_color} hyr-serve thin #{reset_color}# Start web server with Thin - Shortkey" puts "#{example_color} hyraft-server thin #{reset_color}# Start web server with Thin" puts "#{example_color} hyraft-server thin --api #{reset_color}# Start API server with Thin" puts "#{example_color} hyraft-server puma -p 1025 #{reset_color}# Start web server on port 1025" puts "#{example_color} hyraft-server falcon --http2 #{reset_color}# Start with HTTP/2 (Falcon)" puts "#{example_color} hyraft-server s thin #{reset_color}# Legacy syntax (still works)" end |
#start(cmd, args) ⇒ void
This method returns an undefined value.
Start the server with given command and arguments
Supports multiple command formats and server types with comprehensive error handling and user feedback.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/hyraft/server/launcher.rb', line 95 def start(cmd, args) begin # Check if command is a direct server name if %w[thin puma falcon iodine].include?(cmd) @options[:server] = cmd (args) launch_server else case cmd when 'server', 's', 'svr', 'serve' (args) launch_server when 'server-version', 'server-v', 's-v' show_version when 'server-help', 'server-h', 's-h' show_usage when nil, '' puts "#{COLORS[:yellow]}[!] No command provided. Showing help...#{COLORS[:reset]}" show_usage else puts "#{COLORS[:yellow]}[!] Unknown command: '#{cmd}'. Showing help...#{COLORS[:reset]}" show_usage end end rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e puts "#{COLORS[:yellow]}[!] #{e.}#{COLORS[:reset]}" puts "#{COLORS[:yellow]}[!] Falling back to help info...#{COLORS[:reset]}" show_usage rescue => e puts "#{COLORS[:yellow]}[!] Unexpected error: #{e.}#{COLORS[:reset]}" puts "#{COLORS[:yellow]}[!] Showing help for reference...#{COLORS[:reset]}" show_usage end end |