12
13
14
15
16
17
18
19
20
21
22
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
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
|
# File 'lib/tui_td/cli.rb', line 12
def run(argv)
global_opts = {}
command = nil
command_opts = {}
OptionParser.new do |opts|
opts.banner = "Usage: tui-td <command> [options]"
opts.separator ""
opts.separator "Commands:"
opts.separator " serve Start MCP server (JSON-RPC over stdio)"
opts.separator " run <command> Run a TUI app and show live output"
opts.separator " drive <command> Drive a TUI with structured state output"
opts.separator " capture <command> Run once, capture and display state"
opts.separator " test <file> Run JSON test file"
opts.separator " help Show this help"
opts.separator ""
opts.separator "Global options:"
opts.on("-r", "--rows N", Integer, "Terminal rows (default: 40)") do |r|
global_opts[:rows] = r
end
opts.on("-c", "--cols N", Integer, "Terminal cols (default: 120)") do |c|
global_opts[:cols] = c
end
opts.on("-t", "--timeout SECONDS", Integer, "Timeout in seconds (default: 30)") do |t|
global_opts[:timeout] = t
end
opts.on("-C", "--chdir PATH", "Working directory for the command") do |d|
global_opts[:chdir] = d
end
opts.on("--screenshot PATH", "Save screenshot (e.g., output.png)") do |p|
global_opts[:screenshot] = p
end
opts.on("--html PATH", "Save HTML render (e.g., output.html)") do |p|
global_opts[:html] = p
end
opts.on("--json", "Output state as compact JSON") do |_|
global_opts[:format] = :json
end
opts.on("--pretty", "Output state as pretty JSON") do |_|
global_opts[:format] = :pretty_json
end
opts.on("--text", "Output state as plain text table") do |_|
global_opts[:format] = :text
end
opts.on("-h", "--help", "Show help") do
puts opts
exit 0
end
end.permute!(argv)
command = argv.shift
command_opts[:args] = argv
case command
when "serve"
cmd_serve(global_opts)
when "run"
cmd_run(command_opts, global_opts)
when "drive"
cmd_drive(command_opts, global_opts)
when "capture"
cmd_capture(command_opts, global_opts)
when "test"
cmd_test(command_opts, global_opts)
when nil, "help"
puts OptionParser.new { |o| o.banner = "Usage: tui-td <command> [options]" }
exit 0
else
abort "Unknown command: #{command.inspect}\nUse tui-td --help for usage"
end
end
|