mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 23:01:30 +00:00
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:
parent
652ac0fa36
commit
f614892406
3 changed files with 201 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue