diff --git a/.changeset/tender-cups-grin.md b/.changeset/tender-cups-grin.md new file mode 100644 index 000000000000..ad69fdea08f7 --- /dev/null +++ b/.changeset/tender-cups-grin.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Remove --json flag from containers and cloudchamber commands (except for "images list") diff --git a/packages/wrangler/src/__tests__/cloudchamber/apply.test.ts b/packages/wrangler/src/__tests__/cloudchamber/apply.test.ts index 4e3b6bb02aa7..61fead5ebd5a 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/apply.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/apply.test.ts @@ -103,7 +103,7 @@ describe("cloudchamber apply", () => { }); mockGetApplications([]); mockCreateApplication({ id: "abc" } as Application); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stderr).toMatchInlineSnapshot(`""`); expect(std.stdout).toMatchInlineSnapshot(` @@ -176,7 +176,7 @@ describe("cloudchamber apply", () => { }, ]); const applicationReqBodyPromise = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -194,8 +194,6 @@ describe("cloudchamber apply", () => { │ - tier = 3 │ + tier = 2 │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -256,7 +254,7 @@ describe("cloudchamber apply", () => { ]); const res = mockModifyApplication(); mockCreateApplication({ id: "abc" } as Application); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); const body = await res; expect(body).not.toHaveProperty("instances"); /* eslint-disable */ @@ -287,8 +285,6 @@ describe("cloudchamber apply", () => { │ [containers.constraints] │ tier = 1 │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -348,7 +344,7 @@ describe("cloudchamber apply", () => { }, ]); mockCreateApplication({ id: "abc" } as Application); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` @@ -434,7 +430,7 @@ describe("cloudchamber apply", () => { ]); const res = mockModifyApplication(); mockCreateApplication({ id: "abc" } as Application); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); await res; /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` @@ -463,8 +459,6 @@ describe("cloudchamber apply", () => { │ [containers.constraints] │ tier = 1 │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -572,7 +566,7 @@ describe("cloudchamber apply", () => { }, ]); const res = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); await res; /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` @@ -602,8 +596,6 @@ describe("cloudchamber apply", () => { │ - [[containers.configuration.secrets]] │ name = \\"MY_SECRET_2\\" │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -709,7 +701,7 @@ describe("cloudchamber apply", () => { }, }, ]); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -823,7 +815,7 @@ describe("cloudchamber apply", () => { { ...completeApp, version: 1 }, { ...completeApp, version: 1, name: "my-container-app-2", id: "abc2" }, ]); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -936,7 +928,7 @@ describe("cloudchamber apply", () => { }, }, ]); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1050,7 +1042,7 @@ describe("cloudchamber apply", () => { { ...completeApp, version: 1 }, { ...completeApp, version: 1, name: "my-container-app-2", id: "abc2" }, ]); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1108,7 +1100,7 @@ describe("cloudchamber apply", () => { }, ]); const applicationReqBodyPromise = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1127,8 +1119,6 @@ describe("cloudchamber apply", () => { │ [containers.constraints] │ ... │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -1182,7 +1172,7 @@ describe("cloudchamber apply", () => { }, ]); const applicationReqBodyPromise = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1201,8 +1191,6 @@ describe("cloudchamber apply", () => { │ [containers.constraints] │ ... │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -1261,7 +1249,7 @@ describe("cloudchamber apply", () => { }, ]); const applicationReqBodyPromise = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1277,8 +1265,6 @@ describe("cloudchamber apply", () => { │ [containers.constraints] │ ... │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -1337,7 +1323,7 @@ describe("cloudchamber apply", () => { }, ]); const applicationReqBodyPromise = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1353,8 +1339,6 @@ describe("cloudchamber apply", () => { │ [containers.constraints] │ ... │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -1412,7 +1396,7 @@ describe("cloudchamber apply", () => { }, ]); const applicationReqBodyPromise = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1428,8 +1412,6 @@ describe("cloudchamber apply", () => { │ [containers.constraints] │ ... │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -1490,7 +1472,7 @@ describe("cloudchamber apply", () => { }, ]); const applicationReqBodyPromise = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1506,8 +1488,6 @@ describe("cloudchamber apply", () => { │ [containers.constraints] │ ... │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -1568,7 +1548,7 @@ describe("cloudchamber apply", () => { }, }, ]); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1622,7 +1602,7 @@ describe("cloudchamber apply", () => { }, }, ]); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1684,7 +1664,7 @@ describe("cloudchamber apply", () => { }, }, ]); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1720,7 +1700,7 @@ describe("cloudchamber apply", () => { }); mockGetApplications([]); mockCreateApplication({ id: "abc" } as Application); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1794,7 +1774,7 @@ describe("cloudchamber apply", () => { }, ]); const applicationReqBodyPromise = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1818,8 +1798,6 @@ describe("cloudchamber apply", () => { │ - tier = 3 │ + tier = 2 │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ @@ -1874,7 +1852,7 @@ describe("cloudchamber apply", () => { }, ]); const applicationReqBodyPromise = mockModifyApplication(); - await runWrangler("cloudchamber apply --json"); + await runWrangler("cloudchamber apply"); /* eslint-disable */ expect(std.stdout).toMatchInlineSnapshot(` "╭ Deploy a container application deploy changes to your application @@ -1898,8 +1876,6 @@ describe("cloudchamber apply", () => { │ - tier = 3 │ + tier = 2 │ - ├ Loading - │ │ │  SUCCESS  Modified application my-container-app │ diff --git a/packages/wrangler/src/__tests__/cloudchamber/create.test.ts b/packages/wrangler/src/__tests__/cloudchamber/create.test.ts index 3ea3bc7e5dad..7ff776c5cd60 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/create.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/create.test.ts @@ -112,7 +112,6 @@ describe("cloudchamber create", () => { -v, --version Show version number [boolean] OPTIONS - --json Return output as clean JSON [boolean] [default: false] --image Image to use for your deployment [string] --location Location on Cloudflare's network where your deployment will run [string] --var Container environment variables [array] @@ -218,28 +217,6 @@ describe("cloudchamber create", () => { ); }); - it("should fail with a nice message when parameters are missing (json)", async () => { - setIsTTY(false); - setWranglerConfig({}); - await runWrangler("cloudchamber create --image hello:world --json"); - expect(std.out).toMatchInlineSnapshot( - `"{\\"error\\":\\"location is required but it's not passed as an argument\\"}"` - ); - expect(std.err).toMatchInlineSnapshot(`""`); - }); - - it("should fail with a nice message when instance type is set with memory (json)", async () => { - setIsTTY(false); - setWranglerConfig({}); - await runWrangler( - "cloudchamber create --image hello:world --location sfo06 --instance-type dev --memory 400GB --json" - ); - expect(std.out).toMatchInlineSnapshot( - `"{\\"error\\":\\"Field /\\"instance_type/\\" is mutually exclusive with /\\"memory/\\" and /\\"vcpu/\\". These fields cannot be set together.\\"}"` - ); - expect(std.err).toMatchInlineSnapshot(`""`); - }); - it("should create deployment (detects no interactivity)", async () => { setIsTTY(false); setWranglerConfig({}); diff --git a/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts b/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts index ef0a77f3875d..67cf4f188fd5 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts @@ -46,9 +46,8 @@ describe("cloudchamber curl", () => { -v, --version Show version number [boolean] OPTIONS - --json Output json. Use for consistent, machine readable output. [boolean] [default: false] -H, --header Add headers in the form of --header : [array] - -D, --data Add a JSON body to the request [string] + -d, --data Add a JSON body to the request [string] -X, --method [string] [default: \\"GET\\"] -s, --silent Only output response [boolean] -v, --verbose Show version number [boolean] @@ -56,7 +55,7 @@ describe("cloudchamber curl", () => { `); }); - it("should be able to use data flag", async () => { + it("can send data with -d/--data", async () => { setIsTTY(false); setWranglerConfig({}); msw.use( @@ -103,7 +102,83 @@ describe("cloudchamber curl", () => { }); await runWrangler( - "cloudchamber curl /deployments/v2 --json -X POST -D '" + deployment + "'" + "cloudchamber curl /deployments/v2 -X POST -d '" + deployment + "'" + ); + expect(std.err).toMatchInlineSnapshot(`""`); + expect(std.out).toMatchInlineSnapshot(` + "{ + \\"id\\": \\"1\\", + \\"type\\": \\"default\\", + \\"created_at\\": \\"123\\", + \\"account_id\\": \\"123\\", + \\"vcpu\\": 4, + \\"memory\\": \\"400MB\\", + \\"memory_mib\\": 400, + \\"version\\": 1, + \\"image\\": \\"hello\\", + \\"location\\": { + \\"name\\": \\"sfo06\\", + \\"enabled\\": true + }, + \\"network\\": { + \\"mode\\": \\"public\\", + \\"ipv4\\": \\"1.1.1.1\\" + }, + \\"placements_ref\\": \\"http://ref\\", + \\"node_group\\": \\"metal\\" + } + " + `); + }); + + it("supports deprecated -D flag", async () => { + setIsTTY(false); + setWranglerConfig({}); + msw.use( + http.post("*/deployments/v2", async ({ request }) => { + // verify we are hitting the expected url + expect(request.url).toEqual(baseRequestUrl + "deployments/v2"); + // and that the request has the expected content + expect(await request.json()).toEqual({ + image: "hello:world", + location: "sfo06", + ssh_public_key_ids: [], + environment_variables: [ + { + name: "HELLO", + value: "WORLD", + }, + { + name: "YOU", + value: "CONQUERED", + }, + ], + vcpu: 3, + memory_mib: 400, + network: { + assign_ipv4: "predefined", + }, + }); + return HttpResponse.json(MOCK_DEPLOYMENTS_COMPLEX[0]); + }) + ); + + // We need to stringify this for cross-platform compatibility + const deployment = JSON.stringify({ + image: "hello:world", + location: "sfo06", + ssh_public_key_ids: [], + environment_variables: [ + { name: "HELLO", value: "WORLD" }, + { name: "YOU", value: "CONQUERED" }, + ], + vcpu: 3, + memory_mib: 400, + network: { assign_ipv4: "predefined" }, + }); + + await runWrangler( + "cloudchamber curl /deployments/v2 -X POST -D '" + deployment + "'" ); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.out).toMatchInlineSnapshot(` @@ -146,7 +221,7 @@ describe("cloudchamber curl", () => { }) ); await runWrangler( - "cloudchamber curl /test --json --header something:here --header other:thing" + "cloudchamber curl /test --header something:here --header other:thing" ); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.out).toMatchInlineSnapshot(` @@ -155,7 +230,7 @@ describe("cloudchamber curl", () => { `); }); - it("should give response without --json flag set", async () => { + it("works", async () => { setIsTTY(false); setWranglerConfig({}); msw.use( @@ -171,116 +246,112 @@ describe("cloudchamber curl", () => { "cloudchamber curl /deployments/v2 --header something:here" ); expect(std.err).toMatchInlineSnapshot(`""`); - expect(std.out).toMatchInlineSnapshot(` - ">> Body - [ - { - \\"id\\": \\"1\\", - \\"type\\": \\"default\\", - \\"created_at\\": \\"123\\", - \\"account_id\\": \\"123\\", - \\"vcpu\\": 4, - \\"memory\\": \\"400MB\\", - \\"memory_mib\\": 400, - \\"version\\": 1, - \\"image\\": \\"hello\\", - \\"location\\": { - \\"name\\": \\"sfo06\\", - \\"enabled\\": true - }, - \\"network\\": { - \\"mode\\": \\"public\\", - \\"ipv4\\": \\"1.1.1.1\\" - }, - \\"placements_ref\\": \\"http://ref\\", - \\"node_group\\": \\"metal\\" - }, - { - \\"id\\": \\"2\\", - \\"type\\": \\"default\\", - \\"created_at\\": \\"1234\\", - \\"account_id\\": \\"123\\", - \\"vcpu\\": 4, - \\"memory\\": \\"400MB\\", - \\"memory_mib\\": 400, - \\"version\\": 2, - \\"image\\": \\"hello\\", - \\"location\\": { - \\"name\\": \\"sfo06\\", - \\"enabled\\": true - }, - \\"network\\": { - \\"mode\\": \\"public\\", - \\"ipv4\\": \\"1.1.1.2\\" - }, - \\"current_placement\\": { - \\"deployment_version\\": 2, - \\"status\\": { - \\"health\\": \\"running\\" - }, - \\"deployment_id\\": \\"2\\", - \\"terminate\\": false, - \\"created_at\\": \\"123\\", - \\"id\\": \\"1\\" - }, - \\"placements_ref\\": \\"http://ref\\", - \\"node_group\\": \\"metal\\" - }, - { - \\"id\\": \\"3\\", - \\"type\\": \\"default\\", - \\"created_at\\": \\"123\\", - \\"account_id\\": \\"123\\", - \\"vcpu\\": 4, - \\"memory\\": \\"400MB\\", - \\"memory_mib\\": 400, - \\"version\\": 1, - \\"image\\": \\"hello\\", - \\"location\\": { - \\"name\\": \\"sfo06\\", - \\"enabled\\": true - }, - \\"network\\": { - \\"mode\\": \\"public\\", - \\"ipv4\\": \\"1.1.1.1\\" - }, - \\"placements_ref\\": \\"http://ref\\", - \\"node_group\\": \\"metal\\" - }, - { - \\"id\\": \\"4\\", - \\"type\\": \\"default\\", - \\"created_at\\": \\"1234\\", - \\"account_id\\": \\"123\\", - \\"vcpu\\": 4, - \\"memory\\": \\"400MB\\", - \\"memory_mib\\": 400, - \\"version\\": 2, - \\"image\\": \\"hello\\", - \\"location\\": { - \\"name\\": \\"sfo06\\", - \\"enabled\\": true - }, - \\"network\\": { - \\"mode\\": \\"public\\", - \\"ipv4\\": \\"1.1.1.2\\" - }, - \\"current_placement\\": { - \\"deployment_version\\": 2, - \\"status\\": { - \\"health\\": \\"running\\" - }, - \\"deployment_id\\": \\"2\\", - \\"terminate\\": false, - \\"created_at\\": \\"123\\", - \\"id\\": \\"1\\" - }, - \\"placements_ref\\": \\"http://ref\\", - \\"node_group\\": \\"metal\\" - } - ] - " - `); + expect(JSON.parse(std.out)).toEqual([ + { + id: "1", + type: "default", + created_at: "123", + account_id: "123", + vcpu: 4, + memory: "400MB", + memory_mib: 400, + version: 1, + image: "hello", + location: { + name: "sfo06", + enabled: true, + }, + network: { + mode: "public", + ipv4: "1.1.1.1", + }, + placements_ref: "http://ref", + node_group: "metal", + }, + { + id: "2", + type: "default", + created_at: "1234", + account_id: "123", + vcpu: 4, + memory: "400MB", + memory_mib: 400, + version: 2, + image: "hello", + location: { + name: "sfo06", + enabled: true, + }, + network: { + mode: "public", + ipv4: "1.1.1.2", + }, + current_placement: { + deployment_version: 2, + status: { + health: "running", + }, + deployment_id: "2", + terminate: false, + created_at: "123", + id: "1", + }, + placements_ref: "http://ref", + node_group: "metal", + }, + { + id: "3", + type: "default", + created_at: "123", + account_id: "123", + vcpu: 4, + memory: "400MB", + memory_mib: 400, + version: 1, + image: "hello", + location: { + name: "sfo06", + enabled: true, + }, + network: { + mode: "public", + ipv4: "1.1.1.1", + }, + placements_ref: "http://ref", + node_group: "metal", + }, + { + id: "4", + type: "default", + created_at: "1234", + account_id: "123", + vcpu: 4, + memory: "400MB", + memory_mib: 400, + version: 2, + image: "hello", + location: { + name: "sfo06", + enabled: true, + }, + network: { + mode: "public", + ipv4: "1.1.1.2", + }, + current_placement: { + deployment_version: 2, + status: { + health: "running", + }, + deployment_id: "2", + terminate: false, + created_at: "123", + id: "1", + }, + placements_ref: "http://ref", + node_group: "metal", + }, + ]); }); it("should give a response with headers and request-id when verbose flag is set", async () => { @@ -306,7 +377,7 @@ describe("cloudchamber curl", () => { expect(text).toContain("coordinator-request-id"); }); - it("should give a response with headers and request-id when verbose flag is set with --json", async () => { + it("includes headers and request-id in JSON when used with --silent and --verbose", async () => { setIsTTY(false); setWranglerConfig({}); msw.use( @@ -319,7 +390,7 @@ describe("cloudchamber curl", () => { ); await runWrangler( - "cloudchamber curl -v --json /deployments/v2 --header something:here" + "cloudchamber curl -v /deployments/v2 --silent --header something:here" ); expect(std.err).toMatchInlineSnapshot(`""`); const response = JSON.parse(std.out); diff --git a/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts b/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts index d653bafa530f..2e4b5eeb4323 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts @@ -39,10 +39,7 @@ describe("cloudchamber delete", () => { --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] - -v, --version Show version number [boolean] - - OPTIONS - --json Return output as clean JSON [boolean] [default: false]" + -v, --version Show version number [boolean]" `); }); @@ -66,7 +63,7 @@ describe("cloudchamber delete", () => { ); }); - it("can't modify delete due to lack of fields (json)", async () => { + it("can't modify delete due to lack of fields", async () => { setIsTTY(false); expect(std.err).toMatchInlineSnapshot(`""`); await expect( diff --git a/packages/wrangler/src/__tests__/cloudchamber/images.test.ts b/packages/wrangler/src/__tests__/cloudchamber/images.test.ts index 1c2a75245529..545a7da44b92 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/images.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/images.test.ts @@ -1,5 +1,6 @@ import { http, HttpResponse } from "msw"; import patchConsole from "patch-console"; +import { vi } from "vitest"; import { mockAccountId, mockApiToken } from "../helpers/mock-account-id"; import { mockConsoleMethods } from "../helpers/mock-console"; import { useMockIsTTY } from "../helpers/mock-istty"; @@ -8,6 +9,10 @@ import { runInTempDir } from "../helpers/run-in-tmp"; import { runWrangler } from "../helpers/run-wrangler"; import { mockAccount, setWranglerConfig } from "./utils"; +// we want to include the banner to make sure it doesn't show up in the output +// when using --json +vi.unmock("../wrangler-banner"); + describe("cloudchamber image", () => { const std = mockConsoleMethods(); const { setIsTTY } = useMockIsTTY(); @@ -40,10 +45,7 @@ describe("cloudchamber image", () => { --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] - -v, --version Show version number [boolean] - - OPTIONS - --json Return output as clean JSON [boolean] [default: false]" + -v, --version Show version number [boolean]" `); }); @@ -191,10 +193,11 @@ describe("cloudchamber image list", () => { -v, --version Show version number [boolean] OPTIONS - --json Return output as clean JSON [boolean] [default: false] - --filter Regex to filter results [string]" + --filter Regex to filter results [string] + --json Format output as JSON [boolean] [default: false]" `); }); + it("should list images", async () => { setIsTTY(false); setWranglerConfig({}); @@ -239,6 +242,7 @@ describe("cloudchamber image list", () => { three thirty" `); }); + it("should list images with a filter", async () => { setIsTTY(false); setWranglerConfig({}); @@ -279,6 +283,7 @@ describe("cloudchamber image list", () => { two twenty" `); }); + it("should filter out repos with no non-sha tags", async () => { setIsTTY(false); setWranglerConfig({}); @@ -325,6 +330,7 @@ describe("cloudchamber image list", () => { three thirty" `); }); + it("should list repos with json flag set", async () => { setIsTTY(false); setWranglerConfig({}); @@ -385,6 +391,7 @@ describe("cloudchamber image list", () => { ]" `); }); + it("should filter out repos with no non-sha tags in json output", async () => { setIsTTY(false); setWranglerConfig({}); @@ -447,6 +454,7 @@ describe("cloudchamber image list", () => { ]" `); }); + it("should delete images", async () => { setIsTTY(false); setWranglerConfig({}); @@ -503,6 +511,7 @@ describe("cloudchamber image list", () => { expect(std.err).toMatchInlineSnapshot(`""`); expect(std.out).toMatchInlineSnapshot(`"Deleted tag: one:hundred"`); }); + it("should error when provided a repo without a tag", async () => { setIsTTY(false); setWranglerConfig({}); diff --git a/packages/wrangler/src/__tests__/cloudchamber/list.test.ts b/packages/wrangler/src/__tests__/cloudchamber/list.test.ts index 82f81ee479d4..d9eaae850229 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/list.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/list.test.ts @@ -43,7 +43,6 @@ describe("cloudchamber list", () => { -v, --version Show version number [boolean] OPTIONS - --json Return output as clean JSON [boolean] [default: false] --location Filter deployments by location [string] --image Filter deployments by image [string] --state Filter deployments by deployment state [string] diff --git a/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts b/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts index cc4dd667a54c..0722f2c068fd 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts @@ -80,7 +80,6 @@ describe("cloudchamber modify", () => { -v, --version Show version number [boolean] OPTIONS - --json Return output as clean JSON [boolean] [default: false] --var Container environment variables [array] --label Deployment labels [array] --ssh-public-key-id Public SSH key IDs to include in this container. You can add one to your account with \`wrangler cloudchamber ssh create [array] diff --git a/packages/wrangler/src/__tests__/containers/delete.test.ts b/packages/wrangler/src/__tests__/containers/delete.test.ts index 1216b85a67be..d6ba72911164 100644 --- a/packages/wrangler/src/__tests__/containers/delete.test.ts +++ b/packages/wrangler/src/__tests__/containers/delete.test.ts @@ -3,7 +3,6 @@ import patchConsole from "patch-console"; import { mockAccount, setWranglerConfig } from "../cloudchamber/utils"; import { mockAccountId, mockApiToken } from "../helpers/mock-account-id"; import { mockCLIOutput, mockConsoleMethods } from "../helpers/mock-console"; -import { useMockIsTTY } from "../helpers/mock-istty"; import { msw } from "../helpers/msw"; import { runWrangler } from "../helpers/run-wrangler"; @@ -13,7 +12,6 @@ describe("containers delete", () => { const stdCli = mockCLIOutput(); const std = mockConsoleMethods(); - const { setIsTTY } = useMockIsTTY(); mockAccountId(); mockApiToken(); @@ -40,10 +38,7 @@ describe("containers delete", () => { --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] - -v, --version Show version number [boolean] - - OPTIONS - --json Return output as clean JSON [boolean] [default: false]" + -v, --version Show version number [boolean]" `); }); @@ -135,48 +130,4 @@ describe("containers delete", () => { " `); }); - - it("should delete container (json)", async () => { - setIsTTY(false); - setWranglerConfig({}); - msw.use( - http.delete( - "*/applications/:id", - async ({ request }) => { - expect(await request.text()).toEqual(""); - return HttpResponse.json(`{"success": true, "result": {}}`); - }, - { once: true } - ) - ); - await runWrangler(`containers delete --json ${testContainerID}`); - expect(std.err).toMatchInlineSnapshot(`""`); - expect(std.out).toMatchInlineSnapshot(`"{}"`); - }); - - it("should error when trying to delete a non-existant container (json)", async () => { - setIsTTY(false); - setWranglerConfig({}); - msw.use( - http.delete( - "*/applications/*", - async ({ request }) => { - expect(await request.text()).toEqual(""); - return new HttpResponse( - JSON.stringify({ - success: false, - errors: [{ code: 1000, message: "Not Found" }], - }), - { - status: 404, - } - ); - }, - { once: true } - ) - ); - expect(std.err).toMatchInlineSnapshot(`""`); - await runWrangler(`containers delete --json ${testContainerID}`); - expect(std.out).toMatchInlineSnapshot(`"{\\"error\\":\\"Not Found\\"}"`); - }); }); diff --git a/packages/wrangler/src/__tests__/containers/info.test.ts b/packages/wrangler/src/__tests__/containers/info.test.ts index 1c33dba99e4d..d9fb6610ec77 100644 --- a/packages/wrangler/src/__tests__/containers/info.test.ts +++ b/packages/wrangler/src/__tests__/containers/info.test.ts @@ -39,10 +39,7 @@ describe("containers info", () => { --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] - -v, --version Show version number [boolean] - - OPTIONS - --json Return output as clean JSON [boolean] [default: false]" + -v, --version Show version number [boolean]" `); }); diff --git a/packages/wrangler/src/__tests__/containers/list.test.ts b/packages/wrangler/src/__tests__/containers/list.test.ts index e7826735e44b..0a826c9a93f3 100644 --- a/packages/wrangler/src/__tests__/containers/list.test.ts +++ b/packages/wrangler/src/__tests__/containers/list.test.ts @@ -34,10 +34,7 @@ describe("containers list", () => { --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string] -e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string] -h, --help Show help [boolean] - -v, --version Show version number [boolean] - - OPTIONS - --json Return output as clean JSON [boolean] [default: false]" + -v, --version Show version number [boolean]" `); }); diff --git a/packages/wrangler/src/api/startDevWorker/ConfigController.ts b/packages/wrangler/src/api/startDevWorker/ConfigController.ts index 043f315b146e..a2d9322a6946 100644 --- a/packages/wrangler/src/api/startDevWorker/ConfigController.ts +++ b/packages/wrangler/src/api/startDevWorker/ConfigController.ts @@ -21,7 +21,6 @@ import { } from "../../environment-variables/misc-variables"; import { UserError } from "../../errors"; import { getFlag } from "../../experimental-flags"; -import { isNonInteractiveOrCI } from "../../is-interactive"; import { logger, runWithLogLevel } from "../../logger"; import { checkTypesDiff } from "../../type-generation/helpers"; import { @@ -414,11 +413,7 @@ async function resolveConfig( (c) => !isDockerfile(c.image ?? c.configuration?.image) ); if (needsPulling && !resolved.dev.remote) { - await fillOpenAPIConfiguration( - config, - isNonInteractiveOrCI(), - containersScope - ); + await fillOpenAPIConfiguration(config, containersScope); } // TODO(queues) support remote wrangler dev diff --git a/packages/wrangler/src/cloudchamber/apply.ts b/packages/wrangler/src/cloudchamber/apply.ts index 93aecf8c0666..81ea00077803 100644 --- a/packages/wrangler/src/cloudchamber/apply.ts +++ b/packages/wrangler/src/cloudchamber/apply.ts @@ -1,5 +1,4 @@ import { - cancel, endSection, log, logRaw, @@ -8,7 +7,6 @@ import { success, updateStatus, } from "@cloudflare/cli"; -import { processArgument } from "@cloudflare/cli/args"; import { bold, brandColor, dim, green, red } from "@cloudflare/cli/colors"; import { ApiError, @@ -26,8 +24,8 @@ import { diffLines } from "./helpers/diff"; import type { Config } from "../config"; import type { ContainerApp, Observability } from "../config/environment"; import type { - CommonYargsArgvJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + StrictYargsOptionsToInterface, } from "../yargs-types"; import type { Application, @@ -70,7 +68,7 @@ function isObject(value: unknown): value is Record { return typeof value === "object" && value !== null && !Array.isArray(value); } -export function applyCommandOptionalYargs(yargs: CommonYargsArgvJSON) { +export function applyCommandOptionalYargs(yargs: CommonYargsArgv) { return yargs.option("skip-defaults", { requiresArg: true, type: "boolean", @@ -420,7 +418,6 @@ function sortObjectRecursive>( export async function apply( args: { skipDefaults: boolean | undefined; - json: boolean; env?: string; imageUpdateRequired?: boolean; }, @@ -460,7 +457,7 @@ export async function apply( const applications = await promiseSpinner( ApplicationsService.listApplications(), - { json: args.json, message: "Loading applications" } + { message: "Loading applications" } ); applications.forEach((app) => cleanupObservability(app.configuration.observability) @@ -702,21 +699,6 @@ export async function apply( endSection("No changes to be made"); return; } - if (!args.json) { - const yes = await processArgument( - { confirm: undefined }, - "confirm", - { - type: "confirm", - question: "Do you want to apply these changes?", - label: "", - } - ); - if (!yes) { - cancel("Not applying changes"); - return; - } - } function formatError(err: ApiError): string { // TODO: this is bad bad. Please fix like we do in create.ts. @@ -743,7 +725,7 @@ export async function apply( try { application = await promiseSpinner( ApplicationsService.createApplication(action.application), - { json: args.json, message: `creating ${action.application.name}` } + { message: `Creating ${action.application.name}` } ); } catch (err) { if (!(err instanceof Error)) { @@ -824,7 +806,6 @@ export async function apply( kind: action.rollout_kind, }), { - json: args.json, message: `rolling out container version ${action.name}`, } ); @@ -868,14 +849,13 @@ export async function apply( * detects. */ export async function applyCommand( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, config: Config ) { return apply( { skipDefaults: args.skipDefaults, env: args.env, - json: args.json, // For the apply command we want this to default to true // so that the image can be updated if the user modified it. imageUpdateRequired: true, diff --git a/packages/wrangler/src/cloudchamber/build.ts b/packages/wrangler/src/cloudchamber/build.ts index 94044c4a93a8..72b2920bc82c 100644 --- a/packages/wrangler/src/cloudchamber/build.ts +++ b/packages/wrangler/src/cloudchamber/build.ts @@ -20,15 +20,15 @@ import { loadAccount } from "./locations"; import type { Config } from "../config"; import type { ContainerApp } from "../config/environment"; import type { - CommonYargsArgvJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + StrictYargsOptionsToInterface, } from "../yargs-types"; import type { BuildArgs, CompleteAccountCustomer, } from "@cloudflare/containers-shared"; -export function buildYargs(yargs: CommonYargsArgvJSON) { +export function buildYargs(yargs: CommonYargsArgv) { return yargs .positional("PATH", { type: "string", @@ -62,7 +62,7 @@ export function buildYargs(yargs: CommonYargsArgvJSON) { }); } -export function pushYargs(yargs: CommonYargsArgvJSON) { +export function pushYargs(yargs: CommonYargsArgv) { return yargs .option("path-to-docker", { type: "string", @@ -197,7 +197,7 @@ export async function buildAndMaybePush( } export async function buildCommand( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, config: Config ) { // TODO: merge args with Wrangler config if available @@ -226,7 +226,7 @@ export async function buildCommand( } export async function pushCommand( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, _: Config ) { try { diff --git a/packages/wrangler/src/cloudchamber/common.ts b/packages/wrangler/src/cloudchamber/common.ts index 582f2af96587..0ec1ead840fa 100644 --- a/packages/wrangler/src/cloudchamber/common.ts +++ b/packages/wrangler/src/cloudchamber/common.ts @@ -21,13 +21,13 @@ import { getScopes, printScopes, requireApiToken, requireAuth } from "../user"; import { printWranglerBanner } from "../wrangler-banner"; import { parseByteSize } from "./../parse"; import { wrap } from "./helpers/wrap"; -import { idToLocationName, loadAccount } from "./locations"; +import { idToLocationName } from "./locations"; import type { Config } from "../config"; import type { CloudchamberConfig, ContainerApp } from "../config/environment"; import type { containersScope } from "../containers"; import type { CommonYargsOptions, - StrictYargsOptionsToInterfaceJSON, + StrictYargsOptionsToInterface, } from "../yargs-types"; import type { Arg } from "@cloudflare/cli/interactive"; import type { @@ -41,8 +41,6 @@ import type { export const cloudchamberScope = "cloudchamber:write" as const; -export type CommonCloudchamberConfiguration = { json: boolean }; - const containerIdRegexp = /[^/]{36}/; export function isValidContainerID(value: string): boolean { @@ -101,7 +99,7 @@ export function parseImageName(value: string): { */ export function handleFailure< YargsObject, - CommandArgumentsObject = YargsObject extends StrictYargsOptionsToInterfaceJSON< + CommandArgumentsObject = YargsObject extends StrictYargsOptionsToInterface< infer K > ? K @@ -110,47 +108,21 @@ export function handleFailure< command: string, cb: (args: CommandArgumentsObject, config: Config) => Promise, scope: typeof cloudchamberScope | typeof containersScope -): ( - args: CommonYargsOptions & - CommandArgumentsObject & - CommonCloudchamberConfiguration -) => Promise { +): (args: CommonYargsOptions & CommandArgumentsObject) => Promise { return async (args) => { - try { - if (!args.json) { - await printWranglerBanner(); - const commandStatus = command.includes("cloudchamber") - ? "alpha" - : "open-beta"; - logger.warn(constructStatusMessage(command, commandStatus)); - } - const config = readConfig(args); - await fillOpenAPIConfiguration(config, args.json, scope); - await cb(args, config); - } catch (err) { - if (!args.json || !isNonInteractiveOrCI()) { - throw err; - } - - if (err instanceof ApiError) { - logger.log(JSON.stringify(err.body)); - return; - } - - if (err instanceof Error) { - logger.log(JSON.stringify({ error: err.message })); - return; - } - - throw err; + if (!isNonInteractiveOrCI()) { + await printWranglerBanner(); + const commandStatus = command.includes("cloudchamber") + ? "alpha" + : "open-beta"; + logger.warn(constructStatusMessage(command, commandStatus)); } + const config = readConfig(args); + await fillOpenAPIConfiguration(config, scope); + await cb(args, config); }; } -export async function loadAccountSpinner({ json }: { json?: boolean }) { - await promiseSpinner(loadAccount(), { message: "Loading account", json }); -} - /** * Gets the API URL depending if the user is using old/admin based authentication. * @@ -170,14 +142,14 @@ async function getAPIUrl( export async function promiseSpinner( promise: Promise, { - json = false, - message = "Loading", - }: { json?: boolean; message?: string } = { - json: false, + message, + }: { + message: string; + } = { message: "Loading", } ): Promise { - if (json) { + if (isNonInteractiveOrCI()) { return promise; } const { start, stop } = spinner(); @@ -192,7 +164,6 @@ export async function promiseSpinner( export async function fillOpenAPIConfiguration( config: Config, - _json: boolean, scope: typeof containersScope | typeof cloudchamberScope ) { const headers: Record = @@ -225,10 +196,6 @@ export async function fillOpenAPIConfiguration( OpenAPI.HEADERS = headers; } -export function interactWithUser(config: { json?: boolean }): boolean { - return !config.json && !isNonInteractiveOrCI(); -} - type NonObject = undefined | null | boolean | string | number; export type DeepComplete = T extends NonObject diff --git a/packages/wrangler/src/cloudchamber/create.ts b/packages/wrangler/src/cloudchamber/create.ts index 83eefc304642..a3da1cdd1c87 100644 --- a/packages/wrangler/src/cloudchamber/create.ts +++ b/packages/wrangler/src/cloudchamber/create.ts @@ -13,6 +13,7 @@ import { AssignIPv6, DeploymentsService, } from "@cloudflare/containers-shared"; +import { isNonInteractiveOrCI } from "../is-interactive"; import { logger } from "../logger"; import { parseByteSize } from "./../parse"; import { pollSSHKeysUntilCondition, waitForPlacement } from "./cli"; @@ -22,8 +23,6 @@ import { checkInstanceType, collectEnvironmentVariables, collectLabels, - interactWithUser, - loadAccountSpinner, parseImageName, promptForEnvironmentVariables, promptForInstanceType, @@ -38,8 +37,8 @@ import { getNetworkInput } from "./network/network"; import { sshPrompts as promptForSSHKeyAndGetAddedSSHKey } from "./ssh/ssh"; import type { Config } from "../config"; import type { - CommonYargsArgvJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + StrictYargsOptionsToInterface, } from "../yargs-types"; import type { Arg } from "@cloudflare/cli/interactive"; import type { @@ -51,7 +50,7 @@ import type { const defaultContainerImage = "docker.io/cloudflare/hello-world:1.0"; -export function createCommandOptionalYargs(yargs: CommonYargsArgvJSON) { +export function createCommandOptionalYargs(yargs: CommonYargsArgv) { return yargs .option("image", { requiresArg: true, @@ -123,18 +122,16 @@ export function createCommandOptionalYargs(yargs: CommonYargsArgvJSON) { } export async function createCommand( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, config: Config ) { - await loadAccountSpinner(args); - const environmentVariables = collectEnvironmentVariables( [], config, args.var ); const labels = collectLabels(args.label); - if (!interactWithUser(args)) { + if (isNonInteractiveOrCI()) { if (config.cloudchamber.image != undefined && args.image == undefined) { args.image = config.cloudchamber.image; } @@ -187,7 +184,7 @@ export async function createCommand( } async function askWhichSSHKeysDoTheyWantToAdd( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, key: SSHPublicKeyID | undefined ): Promise { const keyItems = await pollSSHKeysUntilCondition(() => true); @@ -266,7 +263,7 @@ async function askWhichSSHKeysDoTheyWantToAdd( } async function handleCreateCommand( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, config: Config, environmentVariables: EnvironmentVariable[] | undefined, labels: Label[] | undefined diff --git a/packages/wrangler/src/cloudchamber/curl.ts b/packages/wrangler/src/cloudchamber/curl.ts index 64d134a9938d..824ac0956d05 100644 --- a/packages/wrangler/src/cloudchamber/curl.ts +++ b/packages/wrangler/src/cloudchamber/curl.ts @@ -22,6 +22,11 @@ export function yargsCurl(args: yargs.Argv) { .option("data", { type: "string", describe: "Add a JSON body to the request", + alias: "d", + }) + .option("data-deprecated", { + type: "string", + hidden: true, alias: "D", }) .option("method", { @@ -43,11 +48,6 @@ export function yargsCurl(args: yargs.Argv) { describe: "Equivalent of using --data-binary @- in curl", type: "boolean", alias: "stdin", - }) - .option("json", { - describe: "Output json. Use for consistent, machine readable output.", - type: "boolean", - default: false, }); } @@ -72,16 +72,16 @@ async function requestFromCmd( method: string; header: (string | number)[] | undefined; data?: string; + dataDeprecated?: string; silent?: boolean; verbose?: boolean; useStdin?: boolean; - json?: boolean; }, _config: Config ): Promise { const requestId = `wrangler-${randomUUID()}`; - if (!args.json && args.verbose) { - logRaw(bold(brandColor("Request id: " + requestId))); + if (args.verbose && !args.silent) { + logRaw(bold(brandColor("Request ID: " + requestId))); } if (args.useStdin) { @@ -98,6 +98,8 @@ async function requestFromCmd( }), { "coordinator-request-id": requestId } ); + + const data = args.data ?? args.dataDeprecated; const res = await request(OpenAPI, { url: args.path, method: args.method as @@ -108,11 +110,11 @@ async function requestFromCmd( | "OPTIONS" | "HEAD" | "PATCH", - body: args.data ? JSON.parse(args.data) : undefined, + body: data ? JSON.parse(data) : undefined, mediaType: "application/json", headers: headers, }); - if (args.json || args.silent) { + if (args.silent) { logRaw( JSON.stringify( !args.verbose @@ -138,15 +140,12 @@ async function requestFromCmd( formatValue: yellow, }) ); + + logRaw(cyanBright(">> Body")); } - logRaw(cyanBright(">> Body")); + const text = JSON.stringify(res, null, 4); - logRaw( - text - .split("\n") - .map((line) => `${brandColor(line)}`) - .join("\n") - ); + logRaw(text); } return; } catch (error) { diff --git a/packages/wrangler/src/cloudchamber/delete.ts b/packages/wrangler/src/cloudchamber/delete.ts index 46ac0f86e086..f366d5ebfcb5 100644 --- a/packages/wrangler/src/cloudchamber/delete.ts +++ b/packages/wrangler/src/cloudchamber/delete.ts @@ -2,16 +2,16 @@ import { cancel, endSection, startSection } from "@cloudflare/cli"; import { inputPrompt } from "@cloudflare/cli/interactive"; import { DeploymentsService } from "@cloudflare/containers-shared"; import { UserError } from "../errors"; +import { isNonInteractiveOrCI } from "../is-interactive"; import { logDeployment, pickDeployment } from "./cli/deployments"; -import { interactWithUser, loadAccountSpinner } from "./common"; import { wrap } from "./helpers/wrap"; import type { Config } from "../config"; import type { - CommonYargsArgvJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + StrictYargsOptionsToInterface, } from "../yargs-types"; -export function deleteCommandOptionalYargs(yargs: CommonYargsArgvJSON) { +export function deleteCommandOptionalYargs(yargs: CommonYargsArgv) { return yargs.positional("deploymentId", { type: "string", demandOption: false, @@ -20,13 +20,10 @@ export function deleteCommandOptionalYargs(yargs: CommonYargsArgvJSON) { } export async function deleteCommand( - deleteArgs: StrictYargsOptionsToInterfaceJSON< - typeof deleteCommandOptionalYargs - >, + deleteArgs: StrictYargsOptionsToInterface, config: Config ) { - await loadAccountSpinner(deleteArgs); - if (!interactWithUser(deleteArgs)) { + if (isNonInteractiveOrCI()) { if (!deleteArgs.deploymentId) { throw new Error( "there needs to be a deploymentId when you can't interact with the wrangler cli" @@ -44,7 +41,7 @@ export async function deleteCommand( } async function handleDeleteCommand( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, _config: Config ) { startSection("Delete your deployment"); diff --git a/packages/wrangler/src/cloudchamber/deploy.ts b/packages/wrangler/src/cloudchamber/deploy.ts index d2d58ab899e7..444d4bb4ae48 100644 --- a/packages/wrangler/src/cloudchamber/deploy.ts +++ b/packages/wrangler/src/cloudchamber/deploy.ts @@ -4,7 +4,6 @@ import { type ContainerApp } from "../config/environment"; import { containersScope } from "../containers"; import { getDockerPath } from "../environment-variables/misc-variables"; import { UserError } from "../errors"; -import { isNonInteractiveOrCI } from "../is-interactive"; import { logger } from "../logger"; import { fetchVersion } from "../versions/api"; import { apply } from "./apply"; @@ -66,11 +65,7 @@ export async function deployContainers( } if (!dryRun) { - await fillOpenAPIConfiguration( - config, - isNonInteractiveOrCI(), - containersScope - ); + await fillOpenAPIConfiguration(config, containersScope); } const pathToDocker = getDockerPath(); for (const container of config.containers) { @@ -126,7 +121,6 @@ export async function deployContainers( await apply( { skipDefaults: false, - json: true, env, imageUpdateRequired: buildResult.pushed, }, diff --git a/packages/wrangler/src/cloudchamber/images/images.ts b/packages/wrangler/src/cloudchamber/images/images.ts index 9c1d17c24667..ad47f0c37adf 100644 --- a/packages/wrangler/src/cloudchamber/images/images.ts +++ b/packages/wrangler/src/cloudchamber/images/images.ts @@ -13,25 +13,21 @@ import { ImageRegistryNotAllowedError, } from "@cloudflare/containers-shared"; import { UserError } from "../../errors"; +import { isNonInteractiveOrCI } from "../../is-interactive"; import { pollRegistriesUntilCondition } from "../cli"; -import { - checkEverythingIsSet, - handleFailure, - interactWithUser, - promiseSpinner, -} from "../common"; +import { checkEverythingIsSet, handleFailure, promiseSpinner } from "../common"; import { wrap } from "../helpers/wrap"; import type { Config } from "../../config"; import type { containersScope } from "../../containers"; import type { - CommonYargsArgvJSON, - CommonYargsArgvSanitizedJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + CommonYargsArgvSanitized, + StrictYargsOptionsToInterface, } from "../../yargs-types"; import type { cloudchamberScope } from "../common"; import type { ImageRegistryPermissions } from "@cloudflare/containers-shared"; -function configureImageRegistryOptionalYargs(yargs: CommonYargsArgvJSON) { +function configureImageRegistryOptionalYargs(yargs: CommonYargsArgv) { return yargs .option("domain", { description: @@ -45,7 +41,7 @@ function configureImageRegistryOptionalYargs(yargs: CommonYargsArgvJSON) { }); } -function credentialsImageRegistryYargs(yargs: CommonYargsArgvJSON) { +function credentialsImageRegistryYargs(yargs: CommonYargsArgv) { return yargs .positional("domain", { type: "string", demandOption: true }) .option("expiration-minutes", { @@ -63,7 +59,7 @@ function credentialsImageRegistryYargs(yargs: CommonYargsArgvJSON) { } export const registriesCommand = ( - yargs: CommonYargsArgvJSON, + yargs: CommonYargsArgv, scope: typeof containersScope | typeof cloudchamberScope ) => { return yargs @@ -75,13 +71,13 @@ export const registriesCommand = ( handleFailure( `wrangler cloudchamber registries configure`, async ( - imageArgs: StrictYargsOptionsToInterfaceJSON< + imageArgs: StrictYargsOptionsToInterface< typeof configureImageRegistryOptionalYargs >, config ) => { // check we are in CI or if the user wants to just use JSON - if (!interactWithUser(args)) { + if (isNonInteractiveOrCI()) { const body = checkEverythingIsSet(imageArgs, [ "domain", "public", @@ -128,7 +124,7 @@ export const registriesCommand = ( return handleFailure( `wrangler cloudchamber registries credentials`, async ( - imageArgs: StrictYargsOptionsToInterfaceJSON< + imageArgs: StrictYargsOptionsToInterface< typeof credentialsImageRegistryYargs >, _config @@ -165,7 +161,7 @@ export const registriesCommand = ( return handleFailure( `wrangler cloudchamber registries remove`, async ( - imageArgs: StrictYargsOptionsToInterfaceJSON< + imageArgs: StrictYargsOptionsToInterface< typeof removeImageRegistryYargs >, _config @@ -186,8 +182,8 @@ export const registriesCommand = ( (args) => handleFailure( `wrangler cloudchamber registries list`, - async (imageArgs: CommonYargsArgvSanitizedJSON, config) => { - if (!interactWithUser(imageArgs)) { + async (_: CommonYargsArgvSanitized, config) => { + if (isNonInteractiveOrCI()) { const registries = await ImageRegistriesService.listImageRegistries(); console.log(JSON.stringify(registries, null, 4)); @@ -200,7 +196,7 @@ export const registriesCommand = ( ); }; -function removeImageRegistryYargs(yargs: CommonYargsArgvJSON) { +function removeImageRegistryYargs(yargs: CommonYargsArgv) { return yargs.positional("domain", { type: "string", demandOption: true, @@ -243,7 +239,7 @@ async function handleListImageRegistriesCommand( } async function handleConfigureImageRegistryCommand( - args: StrictYargsOptionsToInterfaceJSON< + args: StrictYargsOptionsToInterface< typeof configureImageRegistryOptionalYargs >, _config: Config diff --git a/packages/wrangler/src/cloudchamber/images/list.ts b/packages/wrangler/src/cloudchamber/images/list.ts index bb9a09c915c7..0a281003907d 100644 --- a/packages/wrangler/src/cloudchamber/images/list.ts +++ b/packages/wrangler/src/cloudchamber/images/list.ts @@ -8,9 +8,9 @@ import { handleFailure, promiseSpinner } from "../common"; import type { Config } from "../../config"; import type { containersScope } from "../../containers"; import type { - CommonYargsArgvJSON, - CommonYargsArgvSanitizedJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + CommonYargsArgvSanitized, + StrictYargsOptionsToInterface, } from "../../yargs-types"; import type { cloudchamberScope } from "../common"; import type { ImageRegistryPermissions } from "@cloudflare/containers-shared"; @@ -25,7 +25,7 @@ interface TagsResponse { } export const imagesCommand = ( - yargs: CommonYargsArgvJSON, + yargs: CommonYargsArgv, scope: typeof containersScope | typeof cloudchamberScope ) => { return yargs @@ -36,7 +36,7 @@ export const imagesCommand = ( (args) => handleFailure( `wrangler containers images list`, - async (_args: CommonYargsArgvSanitizedJSON, config) => { + async (_args: CommonYargsArgvSanitized, config) => { await handleListImagesCommand(args, config); }, scope @@ -49,7 +49,7 @@ export const imagesCommand = ( (args) => handleFailure( `wrangler containers images delete`, - async (_args: CommonYargsArgvSanitizedJSON, config) => { + async (_args: CommonYargsArgvSanitized, config) => { await handleDeleteImageCommand(args, config); }, scope @@ -57,7 +57,7 @@ export const imagesCommand = ( ); }; -function deleteImageYargs(yargs: CommonYargsArgvJSON) { +function deleteImageYargs(yargs: CommonYargsArgv) { return yargs.positional("image", { type: "string", description: "image to delete", @@ -65,15 +65,21 @@ function deleteImageYargs(yargs: CommonYargsArgvJSON) { }); } -function listImagesYargs(yargs: CommonYargsArgvJSON) { - return yargs.option("filter", { - type: "string", - description: "Regex to filter results", - }); +function listImagesYargs(yargs: CommonYargsArgv) { + return yargs + .option("filter", { + type: "string", + description: "Regex to filter results", + }) + .option("json", { + type: "boolean", + description: "Format output as JSON", + default: false, + }); } async function handleDeleteImageCommand( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, _config: Config ) { try { @@ -103,7 +109,7 @@ async function handleDeleteImageCommand( } logger.log(`Deleted tag: ${args.image}`); }), - { message: "Deleting", json: args.json } + { message: "Deleting" } ); } catch (error) { logger.log(`Error when removing image: ${error}`); @@ -111,7 +117,7 @@ async function handleDeleteImageCommand( } async function handleListImagesCommand( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, config: Config ) { try { @@ -134,7 +140,7 @@ async function handleListImagesCommand( await ListTags(responses, false, args.json); }), - { message: "Listing", json: args.json } + { message: "Listing" } ); } catch (error) { logger.log(`Error listing images: ${error}`); diff --git a/packages/wrangler/src/cloudchamber/index.ts b/packages/wrangler/src/cloudchamber/index.ts index f28e674482f8..4891fc00fc4c 100644 --- a/packages/wrangler/src/cloudchamber/index.ts +++ b/packages/wrangler/src/cloudchamber/index.ts @@ -9,10 +9,10 @@ import { imagesCommand } from "./images/list"; import { listCommand, listDeploymentsYargs } from "./list"; import { modifyCommand, modifyCommandOptionalYargs } from "./modify"; import { sshCommand } from "./ssh/ssh"; -import type { CommonYargsArgvJSON, CommonYargsOptions } from "../yargs-types"; +import type { CommonYargsArgv, CommonYargsOptions } from "../yargs-types"; import type { CommandModule } from "yargs"; -function internalCommands(args: CommonYargsArgvJSON) { +function internalCommands(args: CommonYargsArgv) { try { // Add dynamically an internal module that we can attach internal commands // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -24,7 +24,7 @@ function internalCommands(args: CommonYargsArgvJSON) { } export const cloudchamber = ( - yargs: CommonYargsArgvJSON, + yargs: CommonYargsArgv, subHelp: CommandModule ) => { yargs = internalCommands(yargs); diff --git a/packages/wrangler/src/cloudchamber/list.ts b/packages/wrangler/src/cloudchamber/list.ts index c9af3793125b..bbcaa7ca131a 100644 --- a/packages/wrangler/src/cloudchamber/list.ts +++ b/packages/wrangler/src/cloudchamber/list.ts @@ -14,14 +14,14 @@ import { DeploymentsService, PlacementsService, } from "@cloudflare/containers-shared"; -import isInteractive from "../is-interactive"; +import { isNonInteractiveOrCI } from "../is-interactive"; import { listDeploymentsAndChoose, loadDeployments } from "./cli/deployments"; import { capitalize, statusToColored } from "./cli/util"; -import { loadAccountSpinner, promiseSpinner } from "./common"; +import { promiseSpinner } from "./common"; import type { Config } from "../config"; import type { - CommonYargsArgvJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + StrictYargsOptionsToInterface, } from "../yargs-types"; import type { EventName } from "./enums"; import type { @@ -30,7 +30,7 @@ import type { PlacementWithEvents, } from "@cloudflare/containers-shared"; -export function listDeploymentsYargs(args: CommonYargsArgvJSON) { +export function listDeploymentsYargs(args: CommonYargsArgv) { return args .option("location", { requiresArg: true, @@ -71,14 +71,11 @@ export function listDeploymentsYargs(args: CommonYargsArgvJSON) { } export async function listCommand( - deploymentArgs: StrictYargsOptionsToInterfaceJSON< - typeof listDeploymentsYargs - >, + deploymentArgs: StrictYargsOptionsToInterface, config: Config ) { - await loadAccountSpinner(deploymentArgs); const prefix = (deploymentArgs.deploymentIdPrefix ?? "") as string; - if (deploymentArgs.json || !isInteractive()) { + if (isNonInteractiveOrCI()) { const deployments = ( await DeploymentsService.listDeploymentsV2( undefined, @@ -138,7 +135,7 @@ function eventMessage(event: PlacementEvent, lastEvent: boolean): string { const listCommandHandle = async ( deploymentIdPrefix: string, - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, _config: Config ) => { const keepListIter = true; diff --git a/packages/wrangler/src/cloudchamber/modify.ts b/packages/wrangler/src/cloudchamber/modify.ts index 345a67d96f13..d37bec64350c 100644 --- a/packages/wrangler/src/cloudchamber/modify.ts +++ b/packages/wrangler/src/cloudchamber/modify.ts @@ -2,6 +2,7 @@ import { cancel, startSection } from "@cloudflare/cli"; import { processArgument } from "@cloudflare/cli/args"; import { inputPrompt, spinner } from "@cloudflare/cli/interactive"; import { DeploymentsService } from "@cloudflare/containers-shared"; +import { isNonInteractiveOrCI } from "../is-interactive"; import { pollSSHKeysUntilCondition, waitForPlacement } from "./cli"; import { pickDeployment } from "./cli/deployments"; import { getLocation } from "./cli/locations"; @@ -9,8 +10,6 @@ import { checkInstanceType, collectEnvironmentVariables, collectLabels, - interactWithUser, - loadAccountSpinner, parseImageName, promptForEnvironmentVariables, promptForInstanceType, @@ -24,8 +23,8 @@ import { loadAccount } from "./locations"; import { sshPrompts } from "./ssh/ssh"; import type { Config } from "../config"; import type { - CommonYargsArgvJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + StrictYargsOptionsToInterface, } from "../yargs-types"; import type { DeploymentV2, @@ -33,7 +32,7 @@ import type { SSHPublicKeyID, } from "@cloudflare/containers-shared"; -export function modifyCommandOptionalYargs(yargs: CommonYargsArgvJSON) { +export function modifyCommandOptionalYargs(yargs: CommonYargsArgv) { return yargs .positional("deploymentId", { type: "string", @@ -96,14 +95,10 @@ export function modifyCommandOptionalYargs(yargs: CommonYargsArgvJSON) { } export async function modifyCommand( - modifyArgs: StrictYargsOptionsToInterfaceJSON< - typeof modifyCommandOptionalYargs - >, + modifyArgs: StrictYargsOptionsToInterface, config: Config ) { - await loadAccountSpinner(modifyArgs); - - if (!interactWithUser(modifyArgs)) { + if (isNonInteractiveOrCI()) { if (!modifyArgs.deploymentId) { throw new Error( "there needs to be a deploymentId when you can't interact with the wrangler cli" @@ -147,7 +142,7 @@ export async function modifyCommand( } async function handleSSH( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, config: Config, deployment: DeploymentV2 ): Promise { @@ -203,7 +198,7 @@ async function handleSSH( } async function handleModifyCommand( - args: StrictYargsOptionsToInterfaceJSON, + args: StrictYargsOptionsToInterface, config: Config ) { startSection("Modify deployment"); diff --git a/packages/wrangler/src/cloudchamber/ssh/ssh.ts b/packages/wrangler/src/cloudchamber/ssh/ssh.ts index 1bd4c4392497..0222f37372ed 100644 --- a/packages/wrangler/src/cloudchamber/ssh/ssh.ts +++ b/packages/wrangler/src/cloudchamber/ssh/ssh.ts @@ -14,21 +14,18 @@ import { brandColor, dim } from "@cloudflare/cli/colors"; import { inputPrompt, spinner } from "@cloudflare/cli/interactive"; import { SshPublicKeysService } from "@cloudflare/containers-shared"; import { UserError } from "../../errors"; +import { isNonInteractiveOrCI } from "../../is-interactive"; import { logger } from "../../logger"; import { pollSSHKeysUntilCondition } from "../cli"; -import { - checkEverythingIsSet, - handleFailure, - interactWithUser, -} from "../common"; +import { checkEverythingIsSet, handleFailure } from "../common"; import { wrap } from "../helpers/wrap"; import { validatePublicSSHKeyCLI, validateSSHKey } from "./validate"; import type { Config } from "../../config"; import type { containersScope } from "../../containers"; import type { - CommonYargsArgvJSON, - CommonYargsArgvSanitizedJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + CommonYargsArgvSanitized, + StrictYargsOptionsToInterface, } from "../../yargs-types"; import type { cloudchamberScope } from "../common"; import type { @@ -37,7 +34,7 @@ import type { SSHPublicKeyItem, } from "@cloudflare/containers-shared"; -function createSSHPublicKeyOptionalYargs(yargs: CommonYargsArgvJSON) { +function createSSHPublicKeyOptionalYargs(yargs: CommonYargsArgv) { return yargs .option("name", { type: "string", @@ -76,7 +73,7 @@ async function retrieveSSHKey( } export async function sshPrompts( - args: CommonYargsArgvSanitizedJSON, + args: CommonYargsArgvSanitized, keys: ListSSHPublicKeys | undefined = undefined ): Promise { const [key, prompt] = await shouldPromptForNewSSHKeyAppear(keys); @@ -109,7 +106,7 @@ export async function sshPrompts( } export const sshCommand = ( - yargs: CommonYargsArgvJSON, + yargs: CommonYargsArgv, scope: typeof cloudchamberScope | typeof containersScope ) => { return yargs @@ -120,9 +117,9 @@ export const sshCommand = ( (args) => handleFailure( `wrangler cloudchamber ssh list`, - async (sshArgs: CommonYargsArgvSanitizedJSON, config) => { + async (sshArgs: CommonYargsArgvSanitized, config) => { // check we are in CI or if the user wants to just use JSON - if (!interactWithUser(sshArgs)) { + if (isNonInteractiveOrCI()) { const sshKeys = await SshPublicKeysService.listSshPublicKeys(); console.log(JSON.stringify(sshKeys, null, 4)); return; @@ -141,13 +138,13 @@ export const sshCommand = ( handleFailure( `wrangler cloudchamber ssh create`, async ( - sshArgs: StrictYargsOptionsToInterfaceJSON< + sshArgs: StrictYargsOptionsToInterface< typeof createSSHPublicKeyOptionalYargs >, _config ) => { // check we are in CI or if the user wants to just use JSON - if (!interactWithUser(sshArgs)) { + if (isNonInteractiveOrCI()) { const body = checkEverythingIsSet(sshArgs, ["publicKey", "name"]); const sshKey = await retrieveSSHKey(body.publicKey, { json: true, @@ -308,9 +305,7 @@ async function handleListSSHKeysCommand(_args: unknown, _config: Config) { * */ async function handleCreateSSHPublicKeyCommand( - args: StrictYargsOptionsToInterfaceJSON< - typeof createSSHPublicKeyOptionalYargs - > + args: StrictYargsOptionsToInterface ) { startSection( "Choose an ssh key to add", @@ -329,9 +324,7 @@ async function handleCreateSSHPublicKeyCommand( } async function promptForSSHKey( - args: StrictYargsOptionsToInterfaceJSON< - typeof createSSHPublicKeyOptionalYargs - > + args: StrictYargsOptionsToInterface ): Promise { const { username } = userInfo(); const name = await inputPrompt({ diff --git a/packages/wrangler/src/containers/containers.ts b/packages/wrangler/src/containers/containers.ts index 0acd5274df7e..30f58d082a01 100644 --- a/packages/wrangler/src/containers/containers.ts +++ b/packages/wrangler/src/containers/containers.ts @@ -9,21 +9,20 @@ import { processArgument } from "@cloudflare/cli/args"; import { dim, gray } from "@cloudflare/cli/colors"; import { inputPrompt, spinner } from "@cloudflare/cli/interactive"; import { ApiError, ApplicationsService } from "@cloudflare/containers-shared"; -import { loadAccountSpinner } from "../cloudchamber/common"; import { wrap } from "../cloudchamber/helpers/wrap"; import { UserError } from "../errors"; -import isInteractive from "../is-interactive"; +import { isNonInteractiveOrCI } from "../is-interactive"; import type { Config } from "../config"; import type { - CommonYargsArgvJSON, - StrictYargsOptionsToInterfaceJSON, + CommonYargsArgv, + StrictYargsOptionsToInterface, } from "../yargs-types"; import type { Application, ListApplications, } from "@cloudflare/containers-shared"; -export function deleteYargs(args: CommonYargsArgvJSON) { +export function deleteYargs(args: CommonYargsArgv) { return args.positional("ID", { describe: "id of the containers to delete", type: "string", @@ -31,7 +30,7 @@ export function deleteYargs(args: CommonYargsArgvJSON) { } export async function deleteCommand( - deleteArgs: StrictYargsOptionsToInterfaceJSON, + deleteArgs: StrictYargsOptionsToInterface, _config: Config ) { if (!deleteArgs.ID) { @@ -40,16 +39,9 @@ export async function deleteCommand( ); } - if (deleteArgs.json) { - const container = await ApplicationsService.deleteApplication( - deleteArgs.ID - ); - console.log(JSON.stringify(container, null, 4)); - return; - } - startSection("Delete your container"); - if (isInteractive()) { + + if (!isNonInteractiveOrCI()) { const yes = await inputPrompt({ question: "Are you sure that you want to delete these containers? The associated DO container will lose access to the containers.", @@ -62,10 +54,13 @@ export async function deleteCommand( } } - const [, err] = await wrap( - ApplicationsService.deleteApplication(deleteArgs.ID) - ); - if (err) { + try { + await ApplicationsService.deleteApplication(deleteArgs.ID); + } catch (err) { + if (!(err instanceof Error)) { + throw err; + } + if (err instanceof ApiError) { if (err.status === 400 || err.status === 404) { throw new UserError( @@ -86,7 +81,7 @@ export async function deleteCommand( endSection("Your container has been deleted"); } -export function infoYargs(args: CommonYargsArgvJSON) { +export function infoYargs(args: CommonYargsArgv) { return args.positional("ID", { describe: "id of the containers to view", type: "string", @@ -94,7 +89,7 @@ export function infoYargs(args: CommonYargsArgvJSON) { } export async function infoCommand( - infoArgs: StrictYargsOptionsToInterfaceJSON, + infoArgs: StrictYargsOptionsToInterface, _config: Config ) { if (!infoArgs.ID) { @@ -102,12 +97,11 @@ export async function infoCommand( "You must provide an ID. Use 'wrangler containers list` to view your containers." ); } - if (infoArgs.json || !isInteractive()) { + if (isNonInteractiveOrCI()) { const application = ApplicationsService.getApplication(infoArgs.ID); console.log(JSON.stringify(application, null, 4)); return; } - await loadAccountSpinner(infoArgs); const [application, err] = await wrap( ApplicationsService.getApplication(infoArgs.ID) ); @@ -131,15 +125,15 @@ export async function infoCommand( }); } -export function listYargs(args: CommonYargsArgvJSON) { +export function listYargs(args: CommonYargsArgv) { return args; } export async function listCommand( - listArgs: StrictYargsOptionsToInterfaceJSON, + listArgs: StrictYargsOptionsToInterface, config: Config ) { - if (listArgs.json || !isInteractive()) { + if (isNonInteractiveOrCI()) { const applications = await ApplicationsService.listApplications(); console.log(JSON.stringify(applications, null, 4)); return; @@ -172,7 +166,7 @@ function flatDetails>( } async function listCommandHandle( - _args: StrictYargsOptionsToInterfaceJSON, + _args: StrictYargsOptionsToInterface, _config: Config ) { const keepListIter = true; diff --git a/packages/wrangler/src/containers/index.ts b/packages/wrangler/src/containers/index.ts index a1c589772cbb..0beb7045c491 100644 --- a/packages/wrangler/src/containers/index.ts +++ b/packages/wrangler/src/containers/index.ts @@ -14,13 +14,13 @@ import { listCommand, listYargs, } from "./containers"; -import type { CommonYargsArgvJSON, CommonYargsOptions } from "../yargs-types"; +import type { CommonYargsArgv, CommonYargsOptions } from "../yargs-types"; import type { CommandModule } from "yargs"; export const containersScope = "containers:write" as const; export const containers = ( - yargs: CommonYargsArgvJSON, + yargs: CommonYargsArgv, subHelp: CommandModule ) => { return yargs diff --git a/packages/wrangler/src/index.ts b/packages/wrangler/src/index.ts index 3f6b3cad5945..51cb6e5807b7 100644 --- a/packages/wrangler/src/index.ts +++ b/packages/wrangler/src/index.ts @@ -313,7 +313,6 @@ import { workflowsInstancesTerminateAllCommand } from "./workflows/commands/inst import { workflowsListCommand } from "./workflows/commands/list"; import { workflowsTriggerCommand } from "./workflows/commands/trigger"; import { printWranglerBanner } from "./wrangler-banner"; -import { asJson } from "./yargs-types"; import type { ComplianceConfig } from "./environment-variables/misc-variables"; import type { LoggerLevel } from "./logger"; import type { CommonYargsArgv, SubHelp } from "./yargs-types"; @@ -1147,12 +1146,12 @@ export function createCLIParser(argv: string[]) { // cloudchamber wrangler.command("cloudchamber", false, (cloudchamberArgs) => { - return cloudchamber(asJson(cloudchamberArgs.command(subHelp)), subHelp); + return cloudchamber(cloudchamberArgs.command(subHelp), subHelp); }); // containers wrangler.command("containers", false, (containersArgs) => { - return containers(asJson(containersArgs.command(subHelp)), subHelp); + return containers(containersArgs.command(subHelp), subHelp); }); // [PRIVATE BETA] pubsub diff --git a/packages/wrangler/src/yargs-types.ts b/packages/wrangler/src/yargs-types.ts index f155d0635800..47904e8fff86 100644 --- a/packages/wrangler/src/yargs-types.ts +++ b/packages/wrangler/src/yargs-types.ts @@ -13,17 +13,9 @@ export interface CommonYargsOptions { "experimental-remote-bindings": boolean | undefined; } -/** - * Yargs options included in every wrangler command. - */ -type CommonYargsOptionsJSON = { - json: boolean; -} & CommonYargsOptions; - -export type CommonYargsArgvJSON = Argv; - -export type CommonYargsArgvSanitizedJSON

= - OnlyCamelCase>>; +export type CommonYargsArgvSanitized

= OnlyCamelCase< + RemoveIndex> +>; export type CommonYargsArgv = Argv; @@ -46,22 +38,4 @@ export type StrictYargsOptionsToInterface< ? OnlyCamelCase>> : never; -/** - * Given some Yargs Options function factory, extract the interface - * that corresponds to the yargs arguments, remove index types, and only allow camelCase - */ -export type StrictYargsOptionsToInterfaceJSON< - T extends (yargs: CommonYargsArgvJSON) => Argv, -> = T extends (yargs: CommonYargsArgvJSON) => Argv - ? OnlyCamelCase>> - : never; - -export function asJson(yargs: CommonYargsArgv): CommonYargsArgvJSON { - return yargs.option("json", { - describe: "Return output as clean JSON", - type: "boolean", - default: false, - }); -} - export type SubHelp = CommandModule;