-
-
Notifications
You must be signed in to change notification settings - Fork 619
Expand file tree
/
Copy pathauth.ts
More file actions
65 lines (57 loc) · 1.54 KB
/
auth.ts
File metadata and controls
65 lines (57 loc) · 1.54 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
#!/usr/bin/env node
import { defineCommand } from "citty"
import consola from "consola"
import { PATHS, ensurePaths } from "./lib/paths"
import { state } from "./lib/state"
import { setupGitHubToken } from "./lib/token"
interface RunAuthOptions {
verbose: boolean
showToken: boolean
githubUrl?: string
}
export async function runAuth(options: RunAuthOptions): Promise<void> {
if (options.verbose) {
consola.level = 5
consola.info("Verbose logging enabled")
}
state.showToken = options.showToken
const githubUrl = options.githubUrl ?? process.env.GITHUB_URL
if (githubUrl) {
state.githubUrl = githubUrl
consola.info(`Using GitHub Enterprise URL: ${githubUrl}`)
}
await ensurePaths()
await setupGitHubToken({ force: true })
consola.success("GitHub token written to", PATHS.GITHUB_TOKEN_PATH)
}
export const auth = defineCommand({
meta: {
name: "auth",
description: "Run GitHub auth flow without running the server",
},
args: {
verbose: {
alias: "v",
type: "boolean",
default: false,
description: "Enable verbose logging",
},
"show-token": {
type: "boolean",
default: false,
description: "Show GitHub token on auth",
},
"github-url": {
type: "string",
description:
"GitHub Enterprise URL (e.g., https://github.example.com). Can also be set via GITHUB_URL env var",
},
},
run({ args }) {
return runAuth({
verbose: args.verbose,
showToken: args["show-token"],
githubUrl: args["github-url"],
})
},
})