Skip to content

Commit

Permalink
Added logout, login to help message (#699)
Browse files Browse the repository at this point in the history
Also moved login, logout, and whoami to the bottom of the commands.

Resolves #697
  • Loading branch information
JacobMGEvans authored Mar 30, 2022
1 parent 48fa89b commit ea8e701
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 75 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-kiwis-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

polish: added logout and login to helpstring message.
8 changes: 6 additions & 2 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
Expand All @@ -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.
Expand All @@ -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]
Expand Down
148 changes: 75 additions & 73 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -623,79 +623,6 @@ export async function main(argv: string[]): Promise<void> {
}
);

// 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",
Expand Down Expand Up @@ -2347,6 +2274,81 @@ export async function main(argv: string[]): Promise<void> {
});
});

/**
* 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",
Expand Down

0 comments on commit ea8e701

Please sign in to comment.