Skip to content

Commit 51aedd4

Browse files
authored
Show kv help when run without params (#6937)
1 parent ef78258 commit 51aedd4

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.changeset/cyan-cycles-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix: show help when kv commands are run without parameters

packages/wrangler/src/__tests__/kv.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { writeFileSync } from "node:fs";
22
import { http, HttpResponse } from "msw";
3+
import { endEventLoop } from "./helpers/end-event-loop";
34
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
45
import { mockConsoleMethods } from "./helpers/mock-console";
56
import { clearDialogs, mockConfirm } from "./helpers/mock-dialogs";
@@ -53,6 +54,57 @@ describe("wrangler", () => {
5354
`);
5455
});
5556

57+
it("should show help when no argument is passed", async () => {
58+
await runWrangler("kv");
59+
await endEventLoop();
60+
expect(std.out).toMatchInlineSnapshot(`
61+
"wrangler kv
62+
63+
🗂️ Manage Workers KV Namespaces
64+
65+
COMMANDS
66+
wrangler kv namespace Interact with your Workers KV Namespaces
67+
wrangler kv key Individually manage Workers KV key-value pairs
68+
wrangler kv bulk Interact with multiple Workers KV key-value pairs at once
69+
70+
GLOBAL FLAGS
71+
-j, --experimental-json-config Experimental: support wrangler.json [boolean]
72+
-c, --config Path to .toml configuration file [string]
73+
-e, --env Environment to use for operations and .env files [string]
74+
-h, --help Show help [boolean]
75+
-v, --version Show version number [boolean]"
76+
`);
77+
});
78+
79+
it("should show help when an invalid argument is passed", async () => {
80+
await expect(() => runWrangler("kv asdf")).rejects.toThrow(
81+
"Unknown argument: asdf"
82+
);
83+
expect(std.err).toMatchInlineSnapshot(`
84+
"X [ERROR] Unknown argument: asdf
85+
86+
"
87+
`);
88+
expect(std.out).toMatchInlineSnapshot(`
89+
"
90+
wrangler kv
91+
92+
🗂️ Manage Workers KV Namespaces
93+
94+
COMMANDS
95+
wrangler kv namespace Interact with your Workers KV Namespaces
96+
wrangler kv key Individually manage Workers KV key-value pairs
97+
wrangler kv bulk Interact with multiple Workers KV key-value pairs at once
98+
99+
GLOBAL FLAGS
100+
-j, --experimental-json-config Experimental: support wrangler.json [boolean]
101+
-c, --config Path to .toml configuration file [string]
102+
-e, --env Environment to use for operations and .env files [string]
103+
-h, --help Show help [boolean]
104+
-v, --version Show version number [boolean]"
105+
`);
106+
});
107+
56108
describe("kv namespace", () => {
57109
describe("create", () => {
58110
function mockCreateRequest(expectedTitle: string) {

packages/wrangler/src/kv/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function registerKvSubcommands(
3838
subHelp: SubHelp
3939
) {
4040
return kvYargs
41+
.command(subHelp)
4142
.command(
4243
"namespace",
4344
`Interact with your Workers KV Namespaces`,
@@ -63,6 +64,7 @@ export function registerKvSubcommands(
6364

6465
export function kvNamespace(kvYargs: CommonYargsArgv) {
6566
return kvYargs
67+
.demandCommand()
6668
.command(
6769
"create <namespace>",
6870
"Create a new namespace",
@@ -201,6 +203,7 @@ export function kvNamespace(kvYargs: CommonYargsArgv) {
201203

202204
export const kvKey = (kvYargs: CommonYargsArgv) => {
203205
return kvYargs
206+
.demandCommand()
204207
.command(
205208
"put <key> [value]",
206209
"Write a single key/value pair to the given namespace",
@@ -542,6 +545,7 @@ export const kvKey = (kvYargs: CommonYargsArgv) => {
542545

543546
export const kvBulk = (kvYargs: CommonYargsArgv) => {
544547
return kvYargs
548+
.demandCommand()
545549
.command(
546550
"put <filename>",
547551
"Upload multiple key-value pairs to a namespace",

0 commit comments

Comments
 (0)