diff --git a/.changeset/neat-papers-scream.md b/.changeset/neat-papers-scream.md new file mode 100644 index 0000000..7b714e9 --- /dev/null +++ b/.changeset/neat-papers-scream.md @@ -0,0 +1,9 @@ +--- +"@bunny.net/cli": patch +--- + +Fix `bunny --version` failing with "Unknown argument: version". The +update-check work in a previous release switched yargs to `.version(false)` +plus a manual `--version` option, which interacts badly with strict mode. +The `--version` flag is now intercepted before yargs parses, so the latest +version is still fetched and an upgrade hint shown when outdated. diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 625ca66..6f85267 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -14,7 +14,6 @@ import { registriesNamespace } from "./commands/registries/index.ts"; import { scriptsNamespace } from "./commands/scripts/index.ts"; import { whoamiCommand } from "./commands/whoami.ts"; import { logger } from "./core/logger.ts"; -import { getLatestVersion } from "./core/update-check.ts"; import { VERSION } from "./core/version.ts"; const commands: CommandModule[] = [ @@ -37,12 +36,7 @@ const experimentalCommands: CommandModule[] = [ let instance = yargs(hideBin(process.argv)) .scriptName("bunny") - .version(false) - .option("version", { - type: "boolean", - describe: "Show version number", - global: false, - }) + .version(`${VERSION} ${process.platform}-${process.arch}`) .usage("$0 [options]") .option("profile", { @@ -82,19 +76,7 @@ export const cli = instance "$0", false as never, () => {}, - async (argv) => { - if (argv.version) { - console.log(`${VERSION} ${process.platform}-${process.arch}`); - const latest = await getLatestVersion(); - if (latest && latest !== VERSION) { - console.log( - `\nUpdate available: ${VERSION} → ${latest}` + - `\nRun: npm install -g @bunny.net/cli`, - ); - } - return; - } - + () => { const bunny = chalk.hex("#fb8827"); const art = ` @@@@ diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 5505323..c4ebbf6 100755 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -1,7 +1,21 @@ #!/usr/bin/env bun import { cli } from "./cli.ts"; -import { checkForUpdate } from "./core/update-check.ts"; +import { checkForUpdate, getLatestVersion } from "./core/update-check.ts"; +import { VERSION } from "./core/version.ts"; + +const args = process.argv.slice(2); +if (args.includes("--version") || args.includes("-V")) { + console.log(`${VERSION} ${process.platform}-${process.arch}`); + const latest = await getLatestVersion(); + if (latest && latest !== VERSION) { + console.log( + `\nUpdate available: ${VERSION} → ${latest}` + + `\nRun: npm install -g @bunny.net/cli`, + ); + } + process.exit(0); +} await cli.parse(); await checkForUpdate();