(opts: CommonOptions, deps: AuthDeps = {})
| 242 | } |
| 243 | |
| 244 | export async function runLogout(opts: CommonOptions, deps: AuthDeps = {}): Promise<void> { |
| 245 | const credentialsPath = deps.credentialsPath ?? defaultCredentialsPath(); |
| 246 | const out = makeOutput(opts.output, deps); |
| 247 | const stderr = deps.stderr ?? ((line: string) => process.stderr.write(`${line}\n`)); |
| 248 | |
| 249 | if (opts.dryRun) { |
| 250 | emitDryRunBanner(stderr); |
| 251 | stderr( |
| 252 | `[dry-run] would remove credentials for profile="${opts.profile}" from ${credentialsPath}`, |
| 253 | ); |
| 254 | out.print({ profile: opts.profile, status: 'logged_out' }, data => { |
| 255 | const d = data as { profile: string; status: string }; |
| 256 | return `Removed credentials for profile "${d.profile}" (dry-run).`; |
| 257 | }); |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | const removed = deleteProfile(opts.profile, { path: credentialsPath }); |
| 262 | out.print({ profile: opts.profile, status: removed ? 'logged_out' : 'no_credentials' }, data => { |
| 263 | const d = data as { profile: string; status: string }; |
| 264 | return d.status === 'logged_out' |
| 265 | ? `Removed credentials for profile "${d.profile}".` |
| 266 | : `No credentials stored for profile "${d.profile}".`; |
| 267 | }); |
| 268 | } |
| 269 | |
| 270 | export function createAuthCommand(deps: AuthDeps = {}): Command { |
| 271 | const auth = new Command('auth').description('Manage TestSprite credentials'); |
no test coverage detected