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

Function parseArgs

scripts/obsidian-e2e-cli.mjs:52–95  ·  view source on GitHub ↗
(argv)

Source from the content-addressed store, hash-verified

50}
51
52export function parseArgs(argv) {
53 const instanceArgs = [];
54 const commandArgs = [];
55
56 for (let index = 0; index < argv.length; index += 1) {
57 const arg = argv[index];
58 if (arg === "--") {
59 const next = argv[index + 1];
60 if (
61 index === 0 &&
62 (next === "--help" || BOOLEAN_OPTIONS.has(next) || VALUE_OPTIONS.has(next))
63 ) {
64 continue;
65 }
66 commandArgs.push(...argv.slice(index + 1));
67 break;
68 }
69 if (arg === "--help") {
70 return { help: true, instanceArgs, commandArgs };
71 }
72 if (BOOLEAN_OPTIONS.has(arg)) {
73 instanceArgs.push(arg);
74 continue;
75 }
76 if (VALUE_OPTIONS.has(arg)) {
77 const value = argv[index + 1];
78 if (!value || value.startsWith("--")) {
79 throw new Error(`${arg} requires a value.`);
80 }
81 instanceArgs.push(arg, value);
82 index += 1;
83 continue;
84 }
85
86 commandArgs.push(...argv.slice(index));
87 break;
88 }
89
90 return {
91 help: false,
92 instanceArgs,
93 commandArgs: commandArgs.length > 0 ? commandArgs : ["quickadd:list"],
94 };
95}
96
97export function obsidianEnv(options) {
98 return {

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected