Skip to content

Commit de47a73

Browse files
fix(skill): require a name flag value
1 parent a436530 commit de47a73

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/integrations.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ export async function skillCommand(tokens) {
188188
const rest = tokens.slice(1);
189189
let name, source;
190190
for (let i = 0; i < rest.length; i++) {
191-
if (rest[i] === "--name") name = rest[++i];
191+
if (rest[i] === "--name") {
192+
const next = flagValue(rest, i, rest[i]);
193+
if (next.error) { console.log(err(next.error)); return; }
194+
name = next.value;
195+
i++;
196+
}
192197
else if (!source) source = rest[i];
193198
}
194199
if (!source) { console.log(err("usage: /skill install <git-url|path> [--name <name>]")); return; }

test/skill-command.test.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import assert from "node:assert/strict";
2+
import { spawnSync } from "node:child_process";
3+
import test from "node:test";
4+
import { fileURLToPath } from "node:url";
5+
6+
const BIN = fileURLToPath(new URL("../bin/moshcode.mjs", import.meta.url));
7+
const SOURCE = "https://github.com/acme/cool-skill.git";
8+
9+
for (const extraArgs of [["--name"], ["--name", "--bogus"]]) {
10+
test(`skill install rejects ${extraArgs.join(" ")} without a name value`, () => {
11+
const result = spawnSync(process.execPath, [BIN, "skill", "install", SOURCE, ...extraArgs], {
12+
encoding: "utf8",
13+
});
14+
15+
assert.equal(result.status, 0);
16+
assert.equal(result.stderr, "");
17+
assert.match(result.stdout, /--name requires a value/);
18+
assert.doesNotMatch(result.stdout, /installing skill/);
19+
});
20+
}

0 commit comments

Comments
 (0)