-
Notifications
You must be signed in to change notification settings - Fork 2
automaintainer: Harden supercli's core CLI mechanics and align behavior bet… #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| const { execSync } = require("child_process") | ||
| const path = require("path") | ||
|
|
||
| const CLI = path.join(__dirname, "..", "cli", "supercli.js") | ||
|
|
||
| describe("supercli --version", () => { | ||
| test("--version --human returns version text", () => { | ||
| const out = execSync(`node ${CLI} --version --human`, { | ||
| encoding: "utf-8" | ||
| }) | ||
| expect(out).toContain("SuperCLI v") | ||
| expect(out).toContain("JavaScript") | ||
| }) | ||
|
|
||
| test("--version --json returns version envelope", () => { | ||
| const out = execSync(`node ${CLI} --version --json`, { | ||
| encoding: "utf-8" | ||
| }) | ||
| const data = JSON.parse(out) | ||
| expect(data.name).toBe("SuperCLI") | ||
| expect(data.implementation).toBe("JavaScript") | ||
| expect(data.version).toBeDefined() | ||
| expect(data.node_version).toBeDefined() | ||
| }) | ||
|
|
||
| test("--version alone produces exit code 0 with JSON (non-TTY)", () => { | ||
| const out = execSync(`node ${CLI} --version`, { | ||
| encoding: "utf-8" | ||
| }) | ||
| const data = JSON.parse(out) | ||
| expect(data.name).toBe("SuperCLI") | ||
| expect(data.version).toBe("1.31.1") | ||
| }) | ||
|
|
||
| test("--version --compact returns compact version envelope", () => { | ||
| const out = execSync(`node ${CLI} --version --compact`, { | ||
| encoding: "utf-8" | ||
| }) | ||
| const data = JSON.parse(out) | ||
| expect(data.n).toBe("SuperCLI") | ||
| expect(data.v).toBe("1.31.1") | ||
| }) | ||
| }) | ||
| expect(out).toContain("SuperCLI v") | ||
| expect(out).toContain("JavaScript") | ||
| }) | ||
|
Comment on lines
+43
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The file closes the Useful? React with 👍 / 👎. |
||
|
|
||
| test("--version --json returns version envelope", () => { | ||
| const out = execSync(`node ${CLI} --version --json`, { | ||
| encoding: "utf-8" | ||
| }) | ||
| const data = JSON.parse(out) | ||
| expect(data.name).toBe("SuperCLI") | ||
| expect(data.implementation).toBe("JavaScript") | ||
| expect(data.version).toBeDefined() | ||
| expect(data.node_version).toBeDefined() | ||
| }) | ||
|
|
||
| test("--version alone produces exit code 0", () => { | ||
| const out = execSync(`node ${CLI} --version`, { | ||
| encoding: "utf-8" | ||
| }) | ||
| expect(out).toBeTruthy() | ||
| }) | ||
|
|
||
| test("--version --compact returns compact version envelope", () => { | ||
| const out = execSync(`node ${CLI} --version --compact`, { | ||
| encoding: "utf-8" | ||
| }) | ||
| const data = JSON.parse(out) | ||
| expect(data.name).toBe("SuperCLI") | ||
| expect(data.v).toBeDefined() | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ for (let i = 0; i < rawArgs.length; i++) { | |
| const arg = rawArgs[i]; | ||
| if (arg.startsWith("--")) { | ||
| const kv = arg.slice(2); | ||
| if (kv === "") continue; // bare --, skip (prevents flags[""] = ...) | ||
| const eqIdx = kv.indexOf("="); | ||
| if (eqIdx !== -1) { | ||
| const key = kv.slice(0, eqIdx); | ||
|
|
@@ -71,12 +72,15 @@ const RESERVED_FLAGS = [ | |
| "schema", | ||
| "help-json", | ||
| "help", | ||
| "version", | ||
| "no-color", | ||
| "show-dag", | ||
| "format", | ||
| "on-conflict", | ||
| ]; | ||
|
|
||
| const CLI_VERSION = "1.31.1"; | ||
|
|
||
| function compactKeys(obj) { | ||
| if (Array.isArray(obj)) return obj.map(compactKeys); | ||
| if (obj && typeof obj === "object") { | ||
|
|
@@ -94,6 +98,7 @@ function compactKeys(obj) { | |
| error: "err", | ||
| message: "msg", | ||
| suggestions: "sug", | ||
| name: "n", | ||
| }; | ||
| const out = {}; | ||
| for (const [k, v] of Object.entries(obj)) { | ||
|
|
@@ -176,7 +181,7 @@ function outputError(error) { | |
| ); | ||
| } | ||
| } else { | ||
| console.log(JSON.stringify(compactMode ? compactKeys(envelope) : envelope)); | ||
| process.stderr.write(JSON.stringify(compactMode ? compactKeys(envelope) : envelope) + "\n"); | ||
| } | ||
| process.exit(envelope.error.code); | ||
| } | ||
|
|
@@ -325,6 +330,24 @@ async function main() { | |
| } | ||
| } | ||
|
|
||
| // Early exit for --version (align with Zig CLI behavior) | ||
| if (flags.version) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When any command includes a user argument named Useful? React with 👍 / 👎. |
||
| if (humanMode) { | ||
| console.log(`SuperCLI v${CLI_VERSION}`); | ||
| console.log("Implementation: JavaScript (Node.js)"); | ||
| console.log("Binary: supercli"); | ||
| } else { | ||
| output({ | ||
| name: "SuperCLI", | ||
| implementation: "JavaScript", | ||
| version: CLI_VERSION, | ||
| node_version: process.version, | ||
| binary_name: "supercli", | ||
| }); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Check for namespace passthrough before handling --help | ||
| // This allows commands like "cline --help --json" to pass through | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These leftover lines sit after the
describeblock has already been closed, leaving unmatched braces and making the test file fail to parse before Jest can run anything;node --check __tests__/supercli-args.test.jsreportsSyntaxError: Unexpected token '}'at the duplicated block. Until this is removed, the unit test suite is broken in any environment that loads this file.Useful? React with 👍 / 👎.