-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsave.ts
More file actions
46 lines (42 loc) · 1.6 KB
/
Copy pathsave.ts
File metadata and controls
46 lines (42 loc) · 1.6 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
import { Args, Flags } from "@oclif/core";
import { BaseCommand } from "../lib/base-command";
export default class SaveCommand extends BaseCommand {
static description =
"Save the current ~/.codex/auth.json as a named account (or infer one from auth email)";
static args = {
name: Args.string({
name: "name",
required: false,
description: "Optional account snapshot name. If omitted, inferred from auth email",
}),
} as const;
static flags = {
force: Flags.boolean({
char: "f",
description:
"Force overwrite when the existing snapshot name belongs to a different email account",
default: false,
}),
} as const;
async run(): Promise<void> {
await this.runSafe(async () => {
const { args, flags } = await this.parse(SaveCommand);
const providedName = args.name as string | undefined;
const resolvedName = providedName
? { name: providedName, source: "explicit" as const, forceOverwrite: false }
: await this.accounts.resolveDefaultAccountNameFromCurrentAuth();
const savedName = await this.accounts.saveAccount(resolvedName.name, {
force: Boolean(flags.force || resolvedName.forceOverwrite),
});
const suffix =
resolvedName.source === "explicit"
? ""
: resolvedName.source === "active"
? " (reused active account name)"
: resolvedName.source === "existing"
? " (reused saved account name)"
: " (inferred from auth email)";
this.log(`Saved current Codex auth tokens as "${savedName}"${suffix}.`);
});
}
}