Skip to content

Commit

Permalink
Show kv help when run without params (#6937)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrapoport-cf authored Oct 10, 2024
1 parent ef78258 commit 51aedd4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-cycles-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: show help when kv commands are run without parameters
52 changes: 52 additions & 0 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/wrangler/src/kv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function registerKvSubcommands(
subHelp: SubHelp
) {
return kvYargs
.command(subHelp)
.command(
"namespace",
`Interact with your Workers KV Namespaces`,
Expand All @@ -63,6 +64,7 @@ export function registerKvSubcommands(

export function kvNamespace(kvYargs: CommonYargsArgv) {
return kvYargs
.demandCommand()
.command(
"create <namespace>",
"Create a new namespace",
Expand Down Expand Up @@ -201,6 +203,7 @@ export function kvNamespace(kvYargs: CommonYargsArgv) {

export const kvKey = (kvYargs: CommonYargsArgv) => {
return kvYargs
.demandCommand()
.command(
"put <key> [value]",
"Write a single key/value pair to the given namespace",
Expand Down Expand Up @@ -542,6 +545,7 @@ export const kvKey = (kvYargs: CommonYargsArgv) => {

export const kvBulk = (kvYargs: CommonYargsArgv) => {
return kvYargs
.demandCommand()
.command(
"put <filename>",
"Upload multiple key-value pairs to a namespace",
Expand Down

0 comments on commit 51aedd4

Please sign in to comment.