forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth-list.ts
More file actions
71 lines (64 loc) · 1.66 KB
/
auth-list.ts
File metadata and controls
71 lines (64 loc) · 1.66 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
69
70
71
import { defineCommand } from "citty"
import consola from "consola"
import { readAccountsFile } from "./lib/accounts-loader"
import { ensurePaths } from "./lib/paths"
import { state } from "./lib/state"
import { getGitHubUser } from "./services/github/get-user"
interface RunAuthListOptions {
verbose: boolean
}
export async function runAuthList(options: RunAuthListOptions): Promise<void> {
if (options.verbose) {
consola.level = 5
}
await ensurePaths()
const data = await readAccountsFile()
if (data.accounts.length === 0) {
consola.info("No accounts found. Use `auth add` to add one.")
return
}
const rows: Array<{ name: string; type: string; login: string }> = []
for (const entry of data.accounts) {
let login: string
try {
const user = await getGitHubUser({
account: {
name: entry.name,
accountType: entry.account_type ?? "individual",
githubToken: entry.github_token,
copilotTokenRefreshAt: 0,
inFlight: 0,
lastUsedAt: 0,
failureCount: 0,
},
vsCodeVersion: state.vsCodeVersion,
})
login = user.login
} catch {
login = "(token invalid)"
}
rows.push({
name: entry.name,
type: entry.account_type ?? "individual",
login,
})
}
console.table(rows)
}
export const authList = defineCommand({
meta: {
name: "list",
description: "List all configured GitHub accounts",
},
args: {
verbose: {
alias: "v",
type: "boolean",
default: false,
description: "Enable verbose logging",
},
},
run({ args }) {
return runAuthList({ verbose: args.verbose })
},
})