Skip to content

Commit 6ac9e61

Browse files
committed
prettier login command output
1 parent cb27b72 commit 6ac9e61

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

packages/cli-v3/src/commands/login.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
tracer,
1414
wrapCommandAction,
1515
} from "../cli/common.js";
16-
import { chalkLink } from "../utilities/cliOutput.js";
16+
import { chalkLink, prettyError } from "../utilities/cliOutput.js";
1717
import { readAuthConfigProfile, writeAuthConfigProfile } from "../utilities/configFiles.js";
1818
import { getVersion } from "../utilities/getVersion.js";
1919
import { printInitialBanner } from "../utilities/initialBanner.js";
@@ -109,10 +109,16 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
109109
skipTelemetry: !span.isRecording(),
110110
logLevel: logger.loggerLevel,
111111
},
112-
opts.embedded
112+
true
113113
);
114114

115115
if (!whoAmIResult.success) {
116+
prettyError("Whoami failed", whoAmIResult.error);
117+
118+
if (!opts.embedded) {
119+
outro("Login failed");
120+
}
121+
116122
throw new Error(whoAmIResult.error);
117123
} else {
118124
if (!opts.embedded) {

packages/cli-v3/src/commands/whoami.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { intro, note } from "@clack/prompts";
1+
import { intro, note, outro } from "@clack/prompts";
22
import { chalkLink } from "../utilities/cliOutput.js";
33
import { logger } from "../utilities/logger.js";
44
import { isLoggedIn } from "../utilities/session.js";
@@ -66,11 +66,20 @@ export async function whoAmI(
6666
if (authentication.error === "fetch failed") {
6767
loadingSpinner.stop("Fetch failed. Platform down?");
6868
} else {
69-
loadingSpinner.stop(
70-
`You must login first. Use \`trigger.dev login --profile ${
71-
options?.profile ?? "default"
72-
}\` to login.`
73-
);
69+
if (embedded) {
70+
loadingSpinner.stop(
71+
`Failed to check account details. You may want to run \`trigger.dev logout --profile ${
72+
options?.profile ?? "default"
73+
}\` and try again.`
74+
);
75+
} else {
76+
loadingSpinner.stop(
77+
`You must login first. Use \`trigger.dev login --profile ${
78+
options?.profile ?? "default"
79+
}\` to login.`
80+
);
81+
outro("Whoami failed");
82+
}
7483
}
7584

7685
return {

packages/cli-v3/src/utilities/cliOutput.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ export function prettyPrintDate(date: Date = new Date()) {
6565
return formattedDate;
6666
}
6767

68+
export function prettyError(header: string, body?: string, footer?: string) {
69+
const prefix = "Error: ";
70+
const indent = Array(prefix.length).fill(" ").join("");
71+
const spacing = "\n\n";
72+
73+
const prettyPrefix = chalkError(prefix);
74+
75+
const withIndents = (text?: string) =>
76+
text
77+
?.split("\n")
78+
.map((line) => `${indent}${line}`)
79+
.join("\n");
80+
81+
const prettyBody = withIndents(body);
82+
const prettyFooter = withIndents(footer);
83+
84+
log.error(
85+
`${prettyPrefix}${header}${prettyBody ? `${spacing}${prettyBody}` : ""}${
86+
prettyFooter ? `${spacing}${prettyFooter}` : ""
87+
}`
88+
);
89+
}
90+
6891
export function prettyWarning(header: string, body?: string, footer?: string) {
6992
const prefix = "Warning: ";
7093
const indent = Array(prefix.length).fill(" ").join("");

0 commit comments

Comments
 (0)