Skip to content

Commit

Permalink
Moved login, logout, and whoami to the bottom of the commands. Commen…
Browse files Browse the repository at this point in the history
…t TODO to group the "User" commands.
  • Loading branch information
JacobMGEvans committed Mar 29, 2022
1 parent def1ca0 commit 83b24a5
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 85 deletions.
24 changes: 10 additions & 14 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@ describe("wrangler", () => {
it("should display a list of available commands", async () => {
await runWrangler();

expect(std.out).toMatchInlineSnapshot(
`
expect(std.out).toMatchInlineSnapshot(`
"wrangler
Commands:
wrangler init [name] 📥 Create a wrangler.toml configuration file
wrangler login 🔓 Login to Cloudflare
wrangler logout 🚪 Logout from Cloudflare
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 @@ -49,14 +45,16 @@ 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]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
--legacy-env Use legacy environments [boolean]"
`
);
`);

expect(std.err).toMatchInlineSnapshot(`""`);
});
Expand All @@ -71,15 +69,11 @@ describe("wrangler", () => {
);

expect(std.out).toMatchInlineSnapshot(`""`);
expect(std.err).toMatchInlineSnapshot(
`
expect(std.err).toMatchInlineSnapshot(`
"wrangler
Commands:
wrangler init [name] 📥 Create a wrangler.toml configuration file
wrangler login 🔓 Login to Cloudflare
wrangler logout 🚪 Logout from Cloudflare
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 @@ -89,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 All @@ -97,8 +94,7 @@ describe("wrangler", () => {
--legacy-env Use legacy environments [boolean]
Unknown argument: invalid-command"
`
);
`);
});
});

Expand Down
145 changes: 74 additions & 71 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -623,77 +623,6 @@ export async function main(argv: string[]): Promise<void> {
}
);

// 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();
}
);

// config
wrangler.command(
"config",
Expand Down Expand Up @@ -2345,6 +2274,80 @@ 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
*/
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 83b24a5

Please sign in to comment.