allow interactive mode a --help option

This commit is contained in:
Emil Lerch 2026-05-19 12:35:12 -07:00
parent fa39749980
commit b4db761733
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -77,7 +77,9 @@ const usage_footer =
\\ -w, --watchlist <FILE> Watchlist file (default: watchlist.srf)
\\
\\Interactive command options:
\\ -s, --symbol <SYMBOL> Initial symbol (default: VTI)
\\ -s, --symbol <SYMBOL> Pre-load a symbol and open on the
\\ Quote tab. Without this flag, the TUI
\\ opens on the Portfolio tab.
\\ --chart <MODE> Chart graphics: auto, braille, or WxH
\\ --default-keys Print default keybindings
\\ --default-theme Print default theme
@ -94,6 +96,39 @@ const usage_footer =
\\
;
/// Help text for `zfin interactive --help` / `zfin i --help`.
/// `interactive` is hand-dispatched (not framework-registered) so its
/// help isn't auto-derived from a `Meta.help` field. Kept in sync
/// with the "Interactive command options:" block in `usage_footer`.
const interactive_help =
\\Usage: zfin interactive [options]
\\Alias: zfin i [options]
\\
\\Launch the interactive TUI: a vaxis-rendered, multi-tab terminal
\\interface for browsing your portfolio, per-symbol data, options
\\chains, earnings, and projections. Press `?` inside the TUI to
\\see all keybindings; `q` or Ctrl-C to exit.
\\
\\Options:
\\ -s, --symbol <SYMBOL> Pre-load a symbol and open on the
\\ Quote tab. Without this flag, the TUI
\\ opens on the Portfolio tab.
\\ --chart <MODE> Chart graphics: auto, braille, or WxH
\\ (e.g. 80x24); `auto` picks Kitty graphics
\\ if the terminal supports it, otherwise
\\ braille
\\ --default-keys Print default keybindings as a `keybinds.srf`
\\ template and exit (no TUI launched).
\\ Pipe to `~/.config/zfin/keybinds.srf` to
\\ customize.
\\ --default-theme Print default theme as a `theme.srf`
\\ template and exit (no TUI launched).
\\
\\Global flags (`--no-color`, `-p`, `-w`, `--refresh-data=<value>`)
\\are honored; see `zfin help` for the full list.
\\
;
fn writeUsage(out: *std.Io.Writer) !void {
try cmd_framework.printGroupedUsage(out, @TypeOf(command_modules), command_modules, usage_header, usage_footer);
}
@ -308,6 +343,15 @@ fn runCli(init: std.process.Init) !u8 {
// Interactive TUI: long-lived, per-frame allocations benefit from a
// real (non-arena) allocator. Runs against `gpa` directly.
if (std.mem.eql(u8, command, "interactive") or std.mem.eql(u8, command, "i")) {
// Per-command --help / -h, mirroring the framework dispatch's
// behavior. `interactive` is hand-dispatched (not part of the
// framework registry because it uses gpa, not arena, and bypasses
// DataService construction), so it needs its own --help check.
if (cmd_args.len > 0 and (std.mem.eql(u8, cmd_args[0], "--help") or std.mem.eql(u8, cmd_args[0], "-h"))) {
try out.writeAll(interactive_help);
try out.flush();
return 0;
}
var tui_config = zfin.Config.fromEnv(io, gpa_alloc, init.environ_map);
defer tui_config.deinit();
try out.flush();