Skip to content

Commit 121e624

Browse files
committed
feat: Add auth command to handle GitHub token setup
1 parent 06698a5 commit 121e624

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/auth.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
3+
import { defineCommand } from "citty"
4+
import consola from "consola"
5+
6+
import { PATHS } from "./lib/paths"
7+
import { setupGitHubToken } from "./lib/token"
8+
9+
interface RunAuthOptions {
10+
verbose: boolean
11+
}
12+
13+
export async function runAuth(options: RunAuthOptions): Promise<void> {
14+
if (options.verbose) {
15+
consola.level = 5
16+
consola.info("Verbose logging enabled")
17+
}
18+
19+
await setupGitHubToken()
20+
consola.success("GitHub token written to", PATHS.GITHUB_TOKEN_PATH)
21+
22+
process.exit(0)
23+
}
24+
25+
export const auth = defineCommand({
26+
meta: {
27+
name: "auth",
28+
description: "Run GitHub auth flow without running the server",
29+
},
30+
args: {
31+
verbose: {
32+
alias: "v",
33+
type: "boolean",
34+
default: false,
35+
description: "Enable verbose logging",
36+
},
37+
},
38+
run({ args }) {
39+
return runAuth({
40+
verbose: args.verbose,
41+
})
42+
},
43+
})

src/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { defineCommand, runMain } from "citty"
44
import consola from "consola"
55
import { serve, type ServerHandler } from "srvx"
66

7+
import { auth } from "./auth"
78
import { cacheModels } from "./lib/models"
89
import { ensurePaths } from "./lib/paths"
910
import { state } from "./lib/state"
@@ -51,6 +52,12 @@ export async function runServer(options: RunServerOptions): Promise<void> {
5152
}
5253

5354
const main = defineCommand({
55+
meta: {
56+
name: "copilot-api",
57+
description:
58+
"A wrapper around GitHub Copilot API to make it OpenAI compatible, making it usable for other tools.",
59+
},
60+
subCommands: { auth },
5461
args: {
5562
port: {
5663
alias: "p",

0 commit comments

Comments
 (0)