Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/neat-papers-scream.md
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 2 additions & 20 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand All @@ -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 <command> [options]")

.option("profile", {
Expand Down Expand Up @@ -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 = `
@@@@
Expand Down
16 changes: 15 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -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();