Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
allow to overwrite auth file
Browse files Browse the repository at this point in the history
  • Loading branch information
boristane committed Mar 20, 2022
1 parent a6d8a15 commit a9827c6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ export async function handler(argv: Arguments<Options>) {

try {
const config = await readUserConfig(profile);
outputs.userConfigFound(profile);
} catch (_) {}
if (config) {
outputs.userConfigFound(profile);
const res = await prompts.promptReplaceExistingConfig(profile);
if (!res) {
process.exit(0);
}
}
} catch (_) { }

const accountEmail = email ?? (await prompts.promptForEmail());

Expand Down
1 change: 0 additions & 1 deletion src/commands/auth/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function userConfigFound(profile: string) {
${chalk.bold(`$ baselime auth --profile ${chalk.cyan("new_profile_name")}`)}
${EOL}`);
process.exit(0);
}

export function credentialsConfigured(path: string) {
Expand Down
12 changes: 11 additions & 1 deletion src/commands/auth/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export async function promptForOneTimePassword(email: string): Promise<string> {
return otp;
}

export async function promptReplaceExistingConfig(profile: string): Promise<boolean> {
const { confirm } = await prompt<{ confirm: boolean }>({
type: "confirm",
name: "confirm",
message: `Replace profile ${profile}?`,
});

return confirm;
}

export async function promptForEnvironment(
workspaces: Workspace[],
): Promise<{ workspaceId: string; environmentId: string }> {
Expand All @@ -68,7 +78,7 @@ export async function promptForEnvironment(
choices: environments.map((env) => {
return {
name: env.id,
message: `${chalk.green(
message: `${chalk.cyan(
chalk.bold(`${env.workspace} - ${env.alias}`),
)}`,
value: env.id,
Expand Down
2 changes: 1 addition & 1 deletion src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const baseOptions = {
profile: { type: "string", default: "default" },
"api-key": { type: "string" },
quiet: { type: "boolean", default: false, alias: "q" },
json: { type: "boolean", default: true, conflicts: "output" },
json: { type: "boolean", default: false, conflicts: "output" },
} as const;

0 comments on commit a9827c6

Please sign in to comment.