






















@@ -249,38 +249,46 @@ export function parseArgs(argv) {
249249jsonPath: null,
250250markdownPath: null,
251251};
252+const seen = new Set();
253+const setOnce = (flag, key, value) => {
254+if (seen.has(flag)) {
255+throw new Error(`${flag} was provided more than once.`);
256+}
257+seen.add(flag);
258+options[key] = value;
259+};
252260for (let index = 0; index < argv.length; index += 1) {
253261const arg = argv[index];
254262if (arg === "--") {
255263continue;
256264}
257265if (arg === "--root") {
258-options.rootDir = readRequiredValue(argv, index, "--root");
266+setOnce(arg, "rootDir", readRequiredValue(argv, index, "--root"));
259267index += 1;
260268continue;
261269}
262270if (arg === "--base-ref") {
263-options.baseRef = readRequiredValue(argv, index, "--base-ref");
271+setOnce(arg, "baseRef", readRequiredValue(argv, index, "--base-ref"));
264272index += 1;
265273continue;
266274}
267275if (arg === "--base-lockfile") {
268-options.baseLockfile = readRequiredValue(argv, index, "--base-lockfile");
276+setOnce(arg, "baseLockfile", readRequiredValue(argv, index, "--base-lockfile"));
269277index += 1;
270278continue;
271279}
272280if (arg === "--head-lockfile") {
273-options.headLockfile = readRequiredValue(argv, index, "--head-lockfile");
281+setOnce(arg, "headLockfile", readRequiredValue(argv, index, "--head-lockfile"));
274282index += 1;
275283continue;
276284}
277285if (arg === "--json") {
278-options.jsonPath = readRequiredValue(argv, index, "--json");
286+setOnce(arg, "jsonPath", readRequiredValue(argv, index, "--json"));
279287index += 1;
280288continue;
281289}
282290if (arg === "--markdown") {
283-options.markdownPath = readRequiredValue(argv, index, "--markdown");
291+setOnce(arg, "markdownPath", readRequiredValue(argv, index, "--markdown"));
284292index += 1;
285293continue;
286294}
@@ -289,6 +297,9 @@ export function parseArgs(argv) {
289297if (!options.baseRef && !options.baseLockfile) {
290298throw new Error("Expected --base-ref <git-ref> or --base-lockfile <path>.");
291299}
300+if (options.baseRef && options.baseLockfile) {
301+throw new Error("Use either --base-ref or --base-lockfile, not both.");
302+}
292303return options;
293304}
294305此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。