MCPcopy Create free account
hub / github.com/chhoumann/quickadd / parseArgs

Function parseArgs

scripts/stop-obsidian-e2e-instance.mjs:56–91  ·  view source on GitHub ↗
(argv)

Source from the content-addressed store, hash-verified

54}
55
56export function parseArgs(argv) {
57 const options = { dryRun: false, json: false, prune: false };
58
59 for (let index = 0; index < argv.length; index += 1) {
60 const arg = argv[index];
61 switch (arg) {
62 case "--":
63 break;
64 case "--dry-run":
65 options.dryRun = true;
66 break;
67 case "--prune":
68 options.prune = true;
69 break;
70 case "--json":
71 options.json = true;
72 break;
73 case "--help":
74 options.help = true;
75 break;
76 default: {
77 if (!VALUE_OPTIONS.has(arg)) {
78 throw new Error(`Unknown option: ${arg}`);
79 }
80 const value = argv[index + 1];
81 if (!value || value.startsWith("--")) {
82 throw new Error(`${arg} requires a value.`);
83 }
84 options[toOptionKey(arg)] = value;
85 index += 1;
86 }
87 }
88 }
89
90 return options;
91}
92
93function toOptionKey(arg) {
94 if (arg === "--profile-root") return "profileRoot";

Callers 1

mainFunction · 0.70

Calls 1

toOptionKeyFunction · 0.70

Tested by

no test coverage detected