Add --version/-v flag to CLI (#170)

- Parse --version and -v flags in args.ts
- Handle version flag early in main.ts (print and exit)
- Add flag to help text
- Add comprehensive test coverage for CLI arg parsing

Co-authored-by: cc-vps <crcatala+vps@gmail.com>
This commit is contained in:
Christian Catalan 2025-12-11 18:01:06 -05:00 committed by GitHub
parent 652ac0fa36
commit f614892406
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 201 additions and 0 deletions

View file

@ -19,6 +19,7 @@ export interface Args {
continue?: boolean;
resume?: boolean;
help?: boolean;
version?: boolean;
mode?: Mode;
noSession?: boolean;
session?: string;
@ -48,6 +49,8 @@ export function parseArgs(args: string[]): Args {
if (arg === "--help" || arg === "-h") {
result.help = true;
} else if (arg === "--version" || arg === "-v") {
result.version = true;
} else if (arg === "--mode" && i + 1 < args.length) {
const mode = args[++i];
if (mode === "text" || mode === "json" || mode === "rpc") {
@ -139,6 +142,7 @@ ${chalk.bold("Options:")}
--hook <path> Load a hook file (can be used multiple times)
--export <file> Export session file to HTML and exit
--help, -h Show this help
--version, -v Show version number
${chalk.bold("Examples:")}
# Interactive mode

View file

@ -139,6 +139,11 @@ function prepareInitialMessage(parsed: Args): {
export async function main(args: string[]) {
const parsed = parseArgs(args);
if (parsed.version) {
console.log(VERSION);
return;
}
if (parsed.help) {
printHelp();
return;