forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
68 lines (60 loc) · 2 KB
/
Copy pathcli.ts
File metadata and controls
68 lines (60 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { createInterface } from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
/**
* Prompts the user for a project ID via stdin/stdout.
*/
export async function promptProjectId(): Promise<string> {
const rl = createInterface({ input, output });
try {
const answer = await rl.question("Project ID (leave blank to use your default project): ");
return answer.trim();
} finally {
rl.close();
}
}
/**
* Prompts user whether they want to add another OAuth account.
*/
export async function promptAddAnotherAccount(currentCount: number): Promise<boolean> {
const rl = createInterface({ input, output });
try {
const answer = await rl.question(`Add another account? (${currentCount} added) (y/n): `);
const normalized = answer.trim().toLowerCase();
return normalized === "y" || normalized === "yes";
} finally {
rl.close();
}
}
export type LoginMode = "add" | "fresh";
export interface ExistingAccountInfo {
email?: string;
index: number;
}
/**
* Prompts user to choose login mode when accounts already exist.
* Returns "add" to append new accounts, "fresh" to clear and start over.
*/
export async function promptLoginMode(existingAccounts: ExistingAccountInfo[]): Promise<LoginMode> {
const rl = createInterface({ input, output });
try {
console.log(`\n${existingAccounts.length} account(s) saved:`);
for (const acc of existingAccounts) {
const label = acc.email || `Account ${acc.index + 1}`;
console.log(` ${acc.index + 1}. ${label}`);
}
console.log("");
while (true) {
const answer = await rl.question("(a)dd new account(s) or (f)resh start? [a/f]: ");
const normalized = answer.trim().toLowerCase();
if (normalized === "a" || normalized === "add") {
return "add";
}
if (normalized === "f" || normalized === "fresh") {
return "fresh";
}
console.log("Please enter 'a' to add accounts or 'f' to start fresh.");
}
} finally {
rl.close();
}
}