logout.ts27 lines · main
| 1 | import { clearCredentials, readCredentials, writeCredentials } from '../config.js'; |
| 2 | import { banner, success } from '../output.js'; |
| 3 | |
| 4 | export async function runLogout(argv: readonly string[]): Promise<number> { |
| 5 | const projectArg = parseProject(argv); |
| 6 | banner('logout'); |
| 7 | |
| 8 | if (!projectArg) { |
| 9 | await clearCredentials(); |
| 10 | success('all credentials cleared'); |
| 11 | return 0; |
| 12 | } |
| 13 | |
| 14 | const file = await readCredentials(); |
| 15 | delete file.projects[projectArg]; |
| 16 | if (file.default === projectArg) delete file.default; |
| 17 | await writeCredentials(file); |
| 18 | success(`credentials for ${projectArg} cleared`); |
| 19 | return 0; |
| 20 | } |
| 21 | |
| 22 | function parseProject(argv: readonly string[]): string | null { |
| 23 | for (let i = 0; i < argv.length; i++) { |
| 24 | if (argv[i] === '--project' && argv[i + 1]) return argv[i + 1] ?? null; |
| 25 | } |
| 26 | return null; |
| 27 | } |