diff options
| author | Yuren Hao <97327730+YurenHao0426@users.noreply.github.com> | 2026-09-13 11:07:18 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-13 11:07:18 +0700 |
| commit | c78a5ef589cacb5d7bdc7586b0cc270aded4b5fc (patch) | |
| tree | 69877995c0ecad3eb7266b1bb282c11a6f16dcdf /src/cli/args.ts | |
| parent | 34f22876ab9e15e9f14300a8c21cd7109800d1ab (diff) | |
| parent | 1e81ba361eed444442fa98b0770e7ed78dae864b (diff) | |
Merge pull request #1 from YurenHao0426/agent-cli
Headless CLI mode for agents
Diffstat (limited to 'src/cli/args.ts')
| -rw-r--r-- | src/cli/args.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/cli/args.ts b/src/cli/args.ts new file mode 100644 index 0000000..0f7a767 --- /dev/null +++ b/src/cli/args.ts @@ -0,0 +1,39 @@ +// CLI argument parser + +export interface ParsedArgs { + command: string + positional: string[] + flags: Record<string, string | boolean> +} + +export function parseArgs(argv: string[]): ParsedArgs { + const args = argv.slice(2) + const command = args[0] || '' + const positional: string[] = [] + const flags: Record<string, string | boolean> = {} + + for (let i = 1; i < args.length; i++) { + const arg = args[i] + if (arg.startsWith('--')) { + const eqIdx = arg.indexOf('=') + if (eqIdx !== -1) { + flags[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1) + } else if (i + 1 < args.length && !args[i + 1].startsWith('--')) { + const key = arg.slice(2) + // Boolean flags that never take a value + const boolFlags = new Set(['json', 'dry-run', 'delete', 'force', 'help']) + if (boolFlags.has(key)) { + flags[key] = true + } else { + flags[key] = args[++i] + } + } else { + flags[arg.slice(2)] = true + } + } else { + positional.push(arg) + } + } + + return { command, positional, flags } +} |
