MCPcopy Create free account
hub / github.com/claude-code-internals/claude-code-runnable / parseArgs

Function parseArgs

src/localRecoveryCli.ts:39–89  ·  view source on GitHub ↗
(argv: string[])

Source from the content-addressed store, hash-verified

37}
38
39function parseArgs(argv: string[]) {
40 let print = false
41 let model = process.env.ANTHROPIC_MODEL
42 let systemPrompt: string | undefined
43 let appendSystemPrompt: string | undefined
44 let outputFormat: OutputFormat = 'text'
45 const positional: string[] = []
46
47 for (let i = 0; i < argv.length; i++) {
48 const arg = argv[i]
49 if (!arg) continue
50
51 if (arg === '-h' || arg === '--help') {
52 return { command: 'help' as const }
53 }
54 if (arg === '-v' || arg === '--version' || arg === '-V') {
55 return { command: 'version' as const }
56 }
57 if (arg === '-p' || arg === '--print') {
58 print = true
59 continue
60 }
61 if (arg === '--bare') continue
62 if (arg === '--dangerously-skip-permissions') continue
63 if (arg === '--model') { model = argv[++i]; continue }
64 if (arg === '--system-prompt') { systemPrompt = argv[++i]; continue }
65 if (arg === '--system-prompt-file') {
66 const file = argv[++i]
67 systemPrompt = readFileSync(file!, 'utf8')
68 continue
69 }
70 if (arg === '--append-system-prompt') { appendSystemPrompt = argv[++i]; continue }
71 if (arg === '--output-format') {
72 const value = argv[++i]
73 if (value === 'json' || value === 'text') outputFormat = value
74 continue
75 }
76 if (arg.startsWith('-')) continue
77 positional.push(arg)
78 }
79
80 return {
81 command: 'run' as const,
82 print,
83 model,
84 systemPrompt,
85 appendSystemPrompt,
86 outputFormat,
87 prompt: positional.join(' ').trim(),
88 }
89}
90
91async function readPromptFromStdin(): Promise<string> {
92 if (process.stdin.isTTY) return ''

Callers 1

runFunction · 0.70

Calls 1

readFileSyncFunction · 0.90

Tested by

no test coverage detected