From ea8e7015776b7ac1e15cd14d436d57403a8c5127 Mon Sep 17 00:00:00 2001 From: Jacob M-G Evans <27247160+JacobMGEvans@users.noreply.github.com> Date: Wed, 30 Mar 2022 07:08:12 -0500 Subject: [PATCH] Added logout, login to help message (#699) Also moved login, logout, and whoami to the bottom of the commands. Resolves https://github.com/cloudflare/wrangler2/issues/697 --- .changeset/forty-kiwis-explode.md | 5 + packages/wrangler/src/__tests__/index.test.ts | 8 +- packages/wrangler/src/index.tsx | 148 +++++++++--------- 3 files changed, 86 insertions(+), 75 deletions(-) create mode 100644 .changeset/forty-kiwis-explode.md diff --git a/.changeset/forty-kiwis-explode.md b/.changeset/forty-kiwis-explode.md new file mode 100644 index 000000000000..9da6ea0092b1 --- /dev/null +++ b/.changeset/forty-kiwis-explode.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +polish: added logout and login to helpstring message. diff --git a/packages/wrangler/src/__tests__/index.test.ts b/packages/wrangler/src/__tests__/index.test.ts index ecfa590fe00c..8888256d5275 100644 --- a/packages/wrangler/src/__tests__/index.test.ts +++ b/packages/wrangler/src/__tests__/index.test.ts @@ -36,7 +36,6 @@ describe("wrangler", () => { Commands: wrangler init [name] 📥 Create a wrangler.toml configuration file - wrangler whoami 🕵️ Retrieve your user info and test your auth config wrangler dev [script] 👂 Start a local server for developing your worker wrangler publish [script] 🆙 Publish your Worker to Cloudflare. wrangler tail [name] 🦚 Starts a log tailing session for a published Worker. @@ -46,6 +45,9 @@ describe("wrangler", () => { wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once wrangler pages ⚡️ Configure Cloudflare Pages wrangler r2 📦 Interact with an R2 store + wrangler login 🔓 Login to Cloudflare + wrangler logout 🚪 Logout from Cloudflare + wrangler whoami 🕵️ Retrieve your user info and test your auth config Flags: -c, --config Path to .toml configuration file [string] @@ -72,7 +74,6 @@ describe("wrangler", () => { Commands: wrangler init [name] 📥 Create a wrangler.toml configuration file - wrangler whoami 🕵️ Retrieve your user info and test your auth config wrangler dev [script] 👂 Start a local server for developing your worker wrangler publish [script] 🆙 Publish your Worker to Cloudflare. wrangler tail [name] 🦚 Starts a log tailing session for a published Worker. @@ -82,6 +83,9 @@ describe("wrangler", () => { wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once wrangler pages ⚡️ Configure Cloudflare Pages wrangler r2 📦 Interact with an R2 store + wrangler login 🔓 Login to Cloudflare + wrangler logout 🚪 Logout from Cloudflare + wrangler whoami 🕵️ Retrieve your user info and test your auth config Flags: -c, --config Path to .toml configuration file [string] diff --git a/packages/wrangler/src/index.tsx b/packages/wrangler/src/index.tsx index a8edcb8dcc64..c70ff0db2326 100644 --- a/packages/wrangler/src/index.tsx +++ b/packages/wrangler/src/index.tsx @@ -623,79 +623,6 @@ export async function main(argv: string[]): Promise { } ); - // login - wrangler.command( - // this needs scopes as an option? - "login", - false, // we don't need to show this in the menu - // "🔓 Login to Cloudflare", - (yargs) => { - // TODO: This needs some copy editing - // I mean, this entire app does, but this too. - return yargs - .option("scopes-list", { - describe: "List all the available OAuth scopes with descriptions", - }) - .option("scopes", { - describe: "Pick the set of applicable OAuth scopes when logging in", - array: true, - type: "string", - }); - - // TODO: scopes - }, - async (args) => { - printWranglerBanner(); - if (args["scopes-list"]) { - listScopes(); - return; - } - if (args.scopes) { - if (args.scopes.length === 0) { - // don't allow no scopes to be passed, that would be weird - listScopes(); - return; - } - if (!validateScopeKeys(args.scopes)) { - throw new CommandLineArgsError( - `One of ${args.scopes} is not a valid authentication scope. Run "wrangler login --list-scopes" to see the valid scopes.` - ); - } - await login({ scopes: args.scopes }); - return; - } - await login(); - - // TODO: would be nice if it optionally saved login - // credentials inside node_modules/.cache or something - // this way you could have multiple users on a single machine - } - ); - - // logout - wrangler.command( - // this needs scopes as an option? - "logout", - false, // we don't need to show this in the menu - // "🚪 Logout from Cloudflare", - () => {}, - async () => { - printWranglerBanner(); - await logout(); - } - ); - - // whoami - wrangler.command( - "whoami", - "🕵️ Retrieve your user info and test your auth config", - () => {}, - async () => { - printWranglerBanner(); - await whoami(); - } - ); - // config wrangler.command( "config", @@ -2347,6 +2274,81 @@ export async function main(argv: string[]): Promise { }); }); + /** + * User Group: login, logout, and whoami + * TODO: group commands into User group similar to .group() for flags in yargs + */ + // login + wrangler.command( + // this needs scopes as an option? + "login", + "🔓 Login to Cloudflare", + (yargs) => { + // TODO: This needs some copy editing + // I mean, this entire app does, but this too. + return yargs + .option("scopes-list", { + describe: "List all the available OAuth scopes with descriptions", + }) + .option("scopes", { + describe: "Pick the set of applicable OAuth scopes when logging in", + array: true, + type: "string", + }); + + // TODO: scopes + }, + async (args) => { + printWranglerBanner(); + if (args["scopes-list"]) { + listScopes(); + return; + } + if (args.scopes) { + if (args.scopes.length === 0) { + // don't allow no scopes to be passed, that would be weird + listScopes(); + return; + } + if (!validateScopeKeys(args.scopes)) { + throw new CommandLineArgsError( + `One of ${args.scopes} is not a valid authentication scope. Run "wrangler login --list-scopes" to see the valid scopes.` + ); + } + await login({ scopes: args.scopes }); + return; + } + await login(); + + // TODO: would be nice if it optionally saved login + // credentials inside node_modules/.cache or something + // this way you could have multiple users on a single machine + } + ); + + // logout + wrangler.command( + // this needs scopes as an option? + "logout", + "🚪 Logout from Cloudflare", + () => {}, + async () => { + printWranglerBanner(); + await logout(); + } + ); + + // whoami + wrangler.command( + "whoami", + "🕵️ Retrieve your user info and test your auth config", + () => {}, + async () => { + printWranglerBanner(); + await whoami(); + } + ); + wrangler .option("legacy-env", { type: "boolean",