Skip to content

Commit f9ca072

Browse files
feat(auth): merge workspace picker into use (#94)
## Summary - remove the separate auth workspace select command - make auth workspace use accept an optional workspace id/name - use no-arg auth workspace use for the interactive picker, with the existing single-workspace shortcut and non-interactive multi-workspace usage error - update product docs, command metadata, and auth tests ## Tests - pnpm --filter @prisma/cli test -- auth.test.ts - pnpm --recursive exec tsc --noEmit - pnpm lint
1 parent 9126b1f commit f9ca072

5 files changed

Lines changed: 180 additions & 88 deletions

File tree

docs/product/command-spec.md

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,20 @@ prisma-cli auth workspace list
456456
prisma-cli auth workspace list --json
457457
```
458458

459-
## `prisma-cli auth workspace use <id-or-name>`
459+
## `prisma-cli auth workspace use [id-or-name]`
460460

461461
Purpose:
462462

463-
- switch the local CLI workspace
463+
- switch or interactively select the local CLI workspace
464464

465465
Behavior:
466466

467-
- requires a stored OAuth session for the target workspace
468-
- accepts the cached workspace id, credential workspace id, or cached workspace name case-insensitively
467+
- with `[id-or-name]`, requires a stored OAuth session for the target workspace
468+
- with `[id-or-name]`, accepts the cached workspace id, credential workspace id, or cached workspace name case-insensitively
469+
- without `[id-or-name]`, lists locally authenticated OAuth workspaces in an interactive picker when prompting is available
470+
- without `[id-or-name]`, shows the workspace name and workspace id for each interactive choice
471+
- without `[id-or-name]`, selects the only local OAuth workspace without prompting when exactly one is available
472+
- without `[id-or-name]`, fails in non-interactive mode when more than one local OAuth workspace is available
469473
- changes local CLI context only; it does not mutate a remote resource
470474
- fails with `WORKSPACE_SWITCH_UNAVAILABLE` when `PRISMA_SERVICE_TOKEN` is set
471475
- fails with `WORKSPACE_NOT_AUTHENTICATED` when no cached OAuth session matches
@@ -474,31 +478,11 @@ Behavior:
474478
Examples:
475479

476480
```bash
481+
prisma-cli auth workspace use
477482
prisma-cli auth workspace use wksp_123
478483
prisma-cli auth workspace use "Acme Inc"
479484
```
480485

481-
## `prisma-cli auth workspace select`
482-
483-
Purpose:
484-
485-
- interactively switch the local CLI workspace
486-
487-
Behavior:
488-
489-
- lists locally authenticated OAuth workspaces in an interactive picker
490-
- shows the workspace name and workspace id for each choice
491-
- changes local CLI context only; it does not mutate a remote resource
492-
- fails with `WORKSPACE_SWITCH_UNAVAILABLE` when `PRISMA_SERVICE_TOKEN` is set
493-
- when exactly one local OAuth workspace is available, selects it without prompting
494-
- fails in non-interactive mode when more than one local OAuth workspace is available
495-
496-
Examples:
497-
498-
```bash
499-
prisma-cli auth workspace select
500-
```
501-
502486
## `prisma-cli auth workspace logout <id-or-name>`
503487

504488
Purpose:

packages/cli/src/commands/auth/index.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
runAuthWhoAmI,
99
runAuthWorkspaceList,
1010
runAuthWorkspaceLogout,
11-
runAuthWorkspaceSelect,
1211
runAuthWorkspaceUse,
1312
} from "../../controllers/auth";
1413
import {
@@ -160,7 +159,6 @@ function createAuthWorkspaceCommand(runtime: CliRuntime): Command {
160159

161160
workspace.addCommand(createAuthWorkspaceListCommand(runtime));
162161
workspace.addCommand(createAuthWorkspaceUseCommand(runtime));
163-
workspace.addCommand(createAuthWorkspaceSelectCommand(runtime));
164162
workspace.addCommand(createAuthWorkspaceLogoutCommand(runtime));
165163

166164
return workspace;
@@ -191,31 +189,6 @@ function createAuthWorkspaceListCommand(runtime: CliRuntime): Command {
191189
return command;
192190
}
193191

194-
function createAuthWorkspaceSelectCommand(runtime: CliRuntime): Command {
195-
const command = attachCommandDescriptor(
196-
configureRuntimeCommand(new Command("select"), runtime),
197-
"auth.workspace.select",
198-
);
199-
200-
addGlobalFlags(command);
201-
202-
command.action(async (options) => {
203-
await runCommand<AuthWorkspaceUseResult>(
204-
runtime,
205-
"auth.workspace.select",
206-
options as Record<string, unknown>,
207-
(context) => runAuthWorkspaceSelect(context),
208-
{
209-
renderHuman: (context, descriptor, result) =>
210-
renderAuthWorkspaceUse(context, descriptor, result),
211-
renderJson: (result) => serializeAuthWorkspaceUse(result),
212-
},
213-
);
214-
});
215-
216-
return command;
217-
}
218-
219192
function createAuthWorkspaceLogoutCommand(runtime: CliRuntime): Command {
220193
const command = attachCommandDescriptor(
221194
configureRuntimeCommand(new Command("logout"), runtime),
@@ -252,7 +225,7 @@ function createAuthWorkspaceUseCommand(runtime: CliRuntime): Command {
252225
"auth.workspace.use",
253226
);
254227

255-
command.argument("<id-or-name>", "Workspace id or exact name");
228+
command.argument("[id-or-name]", "Workspace id or exact name");
256229
addGlobalFlags(command);
257230

258231
command.action(async (workspaceRef, options) => {

packages/cli/src/controllers/auth.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,15 @@ export async function runAuthWorkspaceUse(
123123
context: CommandContext,
124124
workspaceRef: string | undefined,
125125
): Promise<CommandSuccess<AuthWorkspaceUseResult>> {
126-
if (!workspaceRef?.trim()) {
127-
throw usageError(
128-
"Workspace required",
129-
"auth workspace use needs a workspace id or cached workspace name.",
130-
"Pass a workspace from prisma-cli auth workspace list.",
131-
["prisma-cli auth workspace list"],
132-
"auth",
133-
);
134-
}
126+
const trimmedWorkspaceRef = workspaceRef?.trim();
127+
const selectedWorkspaceRef = trimmedWorkspaceRef
128+
? trimmedWorkspaceRef
129+
: await selectWorkspaceSession(context);
135130

136131
const result = isRealMode(context)
137-
? await useRealAuthWorkspace(context, workspaceRef)
132+
? await useRealAuthWorkspace(context, selectedWorkspaceRef)
138133
: await createAuthUseCases(createCliUseCaseGateways(context)).useWorkspace(
139-
workspaceRef,
134+
selectedWorkspaceRef,
140135
);
141136

142137
return {
@@ -147,17 +142,6 @@ export async function runAuthWorkspaceUse(
147142
};
148143
}
149144

150-
export async function runAuthWorkspaceSelect(
151-
context: CommandContext,
152-
): Promise<CommandSuccess<AuthWorkspaceUseResult>> {
153-
const workspaceRef = await selectWorkspaceSession(context);
154-
const success = await runAuthWorkspaceUse(context, workspaceRef);
155-
return {
156-
...success,
157-
command: "auth.workspace.select",
158-
};
159-
}
160-
161145
export async function runAuthWorkspaceLogout(
162146
context: CommandContext,
163147
workspaceRef: string | undefined,
@@ -396,7 +380,7 @@ async function selectWorkspaceSession(
396380
if (!canPrompt(context)) {
397381
throw usageError(
398382
"Interactive workspace selection unavailable",
399-
"auth workspace select needs an interactive terminal when more than one workspace is available.",
383+
"auth workspace use needs an interactive terminal when no workspace is provided and more than one workspace is available.",
400384
"Run prisma-cli auth workspace use <id-or-name> with a workspace from prisma-cli auth workspace list.",
401385
["prisma-cli auth workspace list"],
402386
"auth",

packages/cli/src/shell/command-meta.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const DESCRIPTORS: CommandDescriptor[] = [
5656
description: "Manage local authenticated workspaces",
5757
examples: [
5858
"prisma-cli auth workspace list",
59-
"prisma-cli auth workspace select",
59+
"prisma-cli auth workspace use",
6060
"prisma-cli auth workspace use wksp_123",
6161
"prisma-cli auth workspace logout wksp_123",
6262
],
@@ -75,16 +75,11 @@ const DESCRIPTORS: CommandDescriptor[] = [
7575
path: ["prisma", "auth", "workspace", "use"],
7676
description: "Switch the local CLI workspace",
7777
examples: [
78+
"prisma-cli auth workspace use",
7879
"prisma-cli auth workspace use wksp_123",
7980
'prisma-cli auth workspace use "Acme Inc"',
8081
],
8182
},
82-
{
83-
id: "auth.workspace.select",
84-
path: ["prisma", "auth", "workspace", "select"],
85-
description: "Interactively select the local CLI workspace",
86-
examples: ["prisma-cli auth workspace select"],
87-
},
8883
{
8984
id: "auth.workspace.logout",
9085
path: ["prisma", "auth", "workspace", "logout"],

0 commit comments

Comments
 (0)