-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.ts
26 lines (23 loc) · 921 Bytes
/
token.ts
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
import * as commander from "commander";
import { getAuthTokenAsString } from "./auth.js";
export const tokenCommand = ():commander.Command => {
const token = new commander.Command("token");
token.description("Retrive the currently set token from the GitHub CLI.")
.action(async (_options, command: commander.Command) => {
try {
const token: string|undefined = await getAuthTokenAsString();
if (token) {
console.log(token);
return;
} else {
command.error('No token return from `gh auth token` command.',
{ code: 'girt.login.no_token', exitCode: 4 });
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
command.error('Failed executing `gh auth token` command. ' +
err.message, { code: 'girt.login.token_cmd_failed', exitCode: 3 });
}
});
return token;
};