Class: DuoRuby::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/duoruby/cli.rb

Overview

Command-line interface for the duoruby executable.

Commands:

  • help — prints usage information

  • version — prints the gem version

  • serve — starts the HTTP/WebSocket server (accepts --host and --port options)

  • launch — starts the server and opens a native webview window

All commands return an integer exit code. duoruby/server is required lazily by serve to avoid loading Falcon/Async for other commands.

Examples:

Programmatic use (mirrors the exe/duoruby entry point)

exit DuoRuby::CLI.new(ARGV, input: $stdin, output: $stdout).call

Instance Method Summary collapse

Constructor Details

#initialize(args, input:, output:) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • args (Array<String>)

    the command-line arguments (typically ARGV)

  • input (IO)

    standard input (reserved for future interactive use)

  • output (IO)

    standard output where all messages are printed



23
24
25
26
27
# File 'lib/duoruby/cli.rb', line 23

def initialize(args, input:, output:)
  @args = args
  @input = input
  @output = output
end

Instance Method Details

#callInteger

Dispatches to the appropriate command handler.

Returns:

  • (Integer)

    0 on success, 1 on error



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/duoruby/cli.rb', line 32

def call
  case @args.first
  when nil, "help", "--help", "-h"
    help
  when "version", "--version", "-v"
    @output.puts VERSION
    0
  when "serve"
    serve
  when "launch"
    launch
  else
    @output.puts "unknown command: #{@args.first}"
    1
  end
end