MCPcopy Create free account
hub / github.com/cursor/cookbook / parseArgs

Function parseArgs

sdk/coding-agent-cli/src/index.ts:81–143  ·  view source on GitHub ↗
(argv: string[])

Source from the content-addressed store, hash-verified

79}
80
81function parseArgs(argv: string[]): CliOptions {
82 const promptParts: string[] = []
83 let cwd = process.cwd()
84 let force = false
85 let help = false
86 let model = DEFAULT_MODEL
87
88 for (let index = 0; index < argv.length; index += 1) {
89 const arg = argv[index]
90
91 if (arg === "--") {
92 promptParts.push(...argv.slice(index + 1))
93 break
94 }
95
96 if (arg === "--help" || arg === "-h") {
97 help = true
98 continue
99 }
100
101 if (arg === "--force") {
102 force = true
103 continue
104 }
105
106 if (arg === "--cwd" || arg === "-C") {
107 cwd = readOptionValue(argv, index, arg)
108 index += 1
109 continue
110 }
111
112 if (arg.startsWith("--cwd=")) {
113 cwd = arg.slice("--cwd=".length)
114 continue
115 }
116
117 if (arg === "--model" || arg === "-m") {
118 model = readOptionValue(argv, index, arg)
119 index += 1
120 continue
121 }
122
123 if (arg.startsWith("--model=")) {
124 model = arg.slice("--model=".length)
125 continue
126 }
127
128 if (arg.startsWith("-")) {
129 throw new Error(`Unknown option: ${arg}`)
130 }
131
132 promptParts.push(arg, ...argv.slice(index + 1))
133 break
134 }
135
136 return {
137 cwd: path.resolve(cwd),
138 force,

Callers 1

mainFunction · 0.70

Calls 1

readOptionValueFunction · 0.85

Tested by

no test coverage detected