diff --git a/.changeset/cyan-cycles-occur.md b/.changeset/cyan-cycles-occur.md new file mode 100644 index 000000000000..f016ce6ead5a --- /dev/null +++ b/.changeset/cyan-cycles-occur.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +fix: show help when kv commands are run without parameters diff --git a/packages/wrangler/src/__tests__/kv.test.ts b/packages/wrangler/src/__tests__/kv.test.ts index 183fae231ba2..8eb726060ab6 100644 --- a/packages/wrangler/src/__tests__/kv.test.ts +++ b/packages/wrangler/src/__tests__/kv.test.ts @@ -1,5 +1,6 @@ import { writeFileSync } from "node:fs"; import { http, HttpResponse } from "msw"; +import { endEventLoop } from "./helpers/end-event-loop"; import { mockAccountId, mockApiToken } from "./helpers/mock-account-id"; import { mockConsoleMethods } from "./helpers/mock-console"; import { clearDialogs, mockConfirm } from "./helpers/mock-dialogs"; @@ -53,6 +54,57 @@ describe("wrangler", () => { `); }); + it("should show help when no argument is passed", async () => { + await runWrangler("kv"); + await endEventLoop(); + expect(std.out).toMatchInlineSnapshot(` + "wrangler kv + + 🗂️ Manage Workers KV Namespaces + + COMMANDS + wrangler kv namespace Interact with your Workers KV Namespaces + wrangler kv key Individually manage Workers KV key-value pairs + wrangler kv bulk Interact with multiple Workers KV key-value pairs at once + + GLOBAL FLAGS + -j, --experimental-json-config Experimental: support wrangler.json [boolean] + -c, --config Path to .toml configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" + `); + }); + + it("should show help when an invalid argument is passed", async () => { + await expect(() => runWrangler("kv asdf")).rejects.toThrow( + "Unknown argument: asdf" + ); + expect(std.err).toMatchInlineSnapshot(` + "X [ERROR] Unknown argument: asdf + + " + `); + expect(std.out).toMatchInlineSnapshot(` + " + wrangler kv + + 🗂️ Manage Workers KV Namespaces + + COMMANDS + wrangler kv namespace Interact with your Workers KV Namespaces + wrangler kv key Individually manage Workers KV key-value pairs + wrangler kv bulk Interact with multiple Workers KV key-value pairs at once + + GLOBAL FLAGS + -j, --experimental-json-config Experimental: support wrangler.json [boolean] + -c, --config Path to .toml configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" + `); + }); + describe("kv namespace", () => { describe("create", () => { function mockCreateRequest(expectedTitle: string) { diff --git a/packages/wrangler/src/kv/index.ts b/packages/wrangler/src/kv/index.ts index ffa4955ee86b..a2bc7655ee54 100644 --- a/packages/wrangler/src/kv/index.ts +++ b/packages/wrangler/src/kv/index.ts @@ -38,6 +38,7 @@ export function registerKvSubcommands( subHelp: SubHelp ) { return kvYargs + .command(subHelp) .command( "namespace", `Interact with your Workers KV Namespaces`, @@ -63,6 +64,7 @@ export function registerKvSubcommands( export function kvNamespace(kvYargs: CommonYargsArgv) { return kvYargs + .demandCommand() .command( "create ", "Create a new namespace", @@ -201,6 +203,7 @@ export function kvNamespace(kvYargs: CommonYargsArgv) { export const kvKey = (kvYargs: CommonYargsArgv) => { return kvYargs + .demandCommand() .command( "put [value]", "Write a single key/value pair to the given namespace", @@ -542,6 +545,7 @@ export const kvKey = (kvYargs: CommonYargsArgv) => { export const kvBulk = (kvYargs: CommonYargsArgv) => { return kvYargs + .demandCommand() .command( "put ", "Upload multiple key-value pairs to a namespace",