Skip to content

Commit f633f5b

Browse files
committed
feat: support multi-workspace auth in config command
When no LINEAR_API_KEY is set, the config command now uses stored credentials. Single workspace is auto-selected; multiple workspaces prompt the user to choose.
1 parent df59898 commit f633f5b

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/commands/config.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { prompt, Select } from "@cliffy/prompt"
33
import { join } from "@std/path"
44
import { gql } from "../__codegen__/gql.ts"
55
import { getGraphQLClient } from "../utils/graphql.ts"
6+
import { getDefaultWorkspace, getWorkspaces } from "../credentials.ts"
7+
import { getCliWorkspace, getOption, setCliWorkspace } from "../config.ts"
68

79
const configQuery = gql(`
810
query Config {
@@ -33,15 +35,35 @@ export const configCommand = new Command()
3335
███████ ██ ██ ████ ███████ ██ ██ ██ ██ ██████ ███████ ██
3436
`)
3537

36-
const apiKey = Deno.env.get("LINEAR_API_KEY")
37-
if (!apiKey) {
38-
console.error("The LINEAR_API_KEY environment variable is required.")
39-
console.error(
40-
"Create an API key at https://linear.app/settings/account/security",
41-
)
42-
console.error("For bash/zsh, run: export LINEAR_API_KEY=your_key")
43-
console.error("For fish, run: set -gx LINEAR_API_KEY your_key")
44-
Deno.exit(1)
38+
// Check for explicit API key sources (env var, config, or --workspace flag)
39+
const hasExplicitApiKey = Deno.env.get("LINEAR_API_KEY") ||
40+
getOption("api_key") ||
41+
getCliWorkspace()
42+
43+
if (!hasExplicitApiKey) {
44+
const workspaces = getWorkspaces()
45+
if (workspaces.length === 0) {
46+
console.error("No authentication configured.")
47+
console.error("Run `linear auth login` to add a workspace.")
48+
Deno.exit(1)
49+
}
50+
51+
if (workspaces.length === 1) {
52+
// Single workspace - use automatically
53+
setCliWorkspace(workspaces[0])
54+
} else {
55+
// Multiple workspaces - prompt to select
56+
const defaultWorkspace = getDefaultWorkspace()
57+
const selected = await Select.prompt({
58+
message: "Select workspace:",
59+
options: workspaces.map((ws) => ({
60+
name: ws + (ws === defaultWorkspace ? " (default)" : ""),
61+
value: ws,
62+
})),
63+
default: defaultWorkspace,
64+
})
65+
setCliWorkspace(selected)
66+
}
4567
}
4668

4769
const client = getGraphQLClient()

0 commit comments

Comments
 (0)