@@ -3,6 +3,8 @@ import { prompt, Select } from "@cliffy/prompt"
33import { join } from "@std/path"
44import { gql } from "../__codegen__/gql.ts"
55import { getGraphQLClient } from "../utils/graphql.ts"
6+ import { getDefaultWorkspace, getWorkspaces } from "../credentials.ts"
7+ import { getCliWorkspace, getOption, setCliWorkspace } from "../config.ts"
68
79const 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