diff --git a/src/integrations.mjs b/src/integrations.mjs index 345a634..ad10a7f 100644 --- a/src/integrations.mjs +++ b/src/integrations.mjs @@ -188,7 +188,12 @@ export async function skillCommand(tokens) { const rest = tokens.slice(1); let name, source; for (let i = 0; i < rest.length; i++) { - if (rest[i] === "--name") name = rest[++i]; + if (rest[i] === "--name") { + const next = flagValue(rest, i, rest[i]); + if (next.error) { console.log(err(next.error)); return; } + name = next.value; + i++; + } else if (!source) source = rest[i]; } if (!source) { console.log(err("usage: /skill install [--name ]")); return; } diff --git a/test/skill-command.test.mjs b/test/skill-command.test.mjs new file mode 100644 index 0000000..6fb702f --- /dev/null +++ b/test/skill-command.test.mjs @@ -0,0 +1,20 @@ +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import test from "node:test"; +import { fileURLToPath } from "node:url"; + +const BIN = fileURLToPath(new URL("../bin/moshcode.mjs", import.meta.url)); +const SOURCE = "https://github.com/acme/cool-skill.git"; + +for (const extraArgs of [["--name"], ["--name", "--bogus"]]) { + test(`skill install rejects ${extraArgs.join(" ")} without a name value`, () => { + const result = spawnSync(process.execPath, [BIN, "skill", "install", SOURCE, ...extraArgs], { + encoding: "utf8", + }); + + assert.equal(result.status, 0); + assert.equal(result.stderr, ""); + assert.match(result.stdout, /--name requires a value/); + assert.doesNotMatch(result.stdout, /installing skill/); + }); +}