























@@ -29,23 +29,28 @@ function readRefOptionValue(argv, index, optionName) {
2929}
30303131export function parseArgs(argv) {
32+const separatorIndex = argv.indexOf("--");
33+const flagArgv = separatorIndex === -1 ? argv : argv.slice(0, separatorIndex);
34+const explicitPaths =
35+separatorIndex === -1 ? [] : argv.slice(separatorIndex + 1).map(normalizePath);
3236const args = { staged: false, base: "origin/main", head: "HEAD", paths: [] };
33-for (let index = 0; index < argv.length; index += 1) {
34-const arg = argv[index];
35-if (arg === "--") {
36-continue;
37-} else if (arg === "--staged") {
37+for (let index = 0; index < flagArgv.length; index += 1) {
38+const arg = flagArgv[index];
39+if (arg === "--staged") {
3840args.staged = true;
3941} else if (arg === "--base") {
40-args.base = readRefOptionValue(argv, index, arg);
42+args.base = readRefOptionValue(flagArgv, index, arg);
4143index += 1;
4244} else if (arg === "--head") {
43-args.head = readRefOptionValue(argv, index, arg);
45+args.head = readRefOptionValue(flagArgv, index, arg);
4446index += 1;
47+} else if (arg.startsWith("-")) {
48+throw new Error(`Unknown option: ${arg}`);
4549} else {
4650args.paths.push(normalizePath(arg));
4751}
4852}
53+args.paths.push(...explicitPaths);
4954return args;
5055}
5156@@ -164,5 +169,10 @@ export function main(argv = process.argv.slice(2)) {
164169}
165170166171if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(import.meta.filename)) {
167-main();
172+try {
173+main();
174+} catch (error) {
175+console.error(error instanceof Error ? error.message : String(error));
176+process.exit(1);
177+}
168178}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。