@@ -13,6 +13,9 @@ import {
13
13
import { z } from "zod" ;
14
14
import { CliApiClient } from "../apiClient.js" ;
15
15
import { spinner } from "../utilities/windows.js" ;
16
+ import { loadConfig } from "../config.js" ;
17
+ import { resolveLocalEnvVars } from "../utilities/localEnvVars.js" ;
18
+ import { tryCatch } from "@trigger.dev/core" ;
16
19
17
20
type WhoAmIResult =
18
21
| {
@@ -21,20 +24,36 @@ type WhoAmIResult =
21
24
userId : string ;
22
25
email : string ;
23
26
dashboardUrl : string ;
27
+ projectUrl ?: string ;
24
28
} ;
25
29
}
26
30
| {
27
31
success : false ;
28
32
error : string ;
29
33
} ;
30
34
31
- const WhoamiCommandOptions = CommonCommandOptions ;
35
+ const WhoamiCommandOptions = CommonCommandOptions . extend ( {
36
+ config : z . string ( ) . optional ( ) ,
37
+ projectRef : z . string ( ) . optional ( ) ,
38
+ envFile : z . string ( ) . optional ( ) ,
39
+ } ) ;
32
40
33
41
type WhoamiCommandOptions = z . infer < typeof WhoamiCommandOptions > ;
34
42
35
43
export function configureWhoamiCommand ( program : Command ) {
36
44
return commonOptions (
37
- program . command ( "whoami" ) . description ( "display the current logged in user and project details" )
45
+ program
46
+ . command ( "whoami" )
47
+ . description ( "display the current logged in user and project details" )
48
+ . option ( "-c, --config <config file>" , "The name of the config file" )
49
+ . option (
50
+ "-p, --project-ref <project ref>" ,
51
+ "The project ref. This will override the project specified in the config file."
52
+ )
53
+ . option (
54
+ "--env-file <env file>" ,
55
+ "Path to the .env file to load into the CLI process. Defaults to .env in the project directory."
56
+ )
38
57
) . action ( async ( options ) => {
39
58
await handleTelemetry ( async ( ) => {
40
59
await printInitialBanner ( false ) ;
@@ -58,6 +77,23 @@ export async function whoAmI(
58
77
intro ( `Displaying your account details [${ options ?. profile ?? "default" } ]` ) ;
59
78
}
60
79
80
+ const envVars = resolveLocalEnvVars ( options ?. envFile ) ;
81
+
82
+ if ( envVars . TRIGGER_PROJECT_REF ) {
83
+ logger . debug ( "Using project ref from env" , { ref : envVars . TRIGGER_PROJECT_REF } ) ;
84
+ }
85
+
86
+ const [ configError , resolvedConfig ] = await tryCatch (
87
+ loadConfig ( {
88
+ overrides : { project : options ?. projectRef ?? envVars . TRIGGER_PROJECT_REF } ,
89
+ configFile : options ?. config ,
90
+ } )
91
+ ) ;
92
+
93
+ if ( configError ) {
94
+ logger . debug ( "Error loading config" , { error : configError } ) ;
95
+ }
96
+
61
97
const loadingSpinner = spinner ( ) ;
62
98
63
99
if ( ! silent ) {
@@ -94,7 +130,7 @@ export async function whoAmI(
94
130
}
95
131
96
132
const apiClient = new CliApiClient ( authentication . auth . apiUrl , authentication . auth . accessToken ) ;
97
- const userData = await apiClient . whoAmI ( ) ;
133
+ const userData = await apiClient . whoAmI ( resolvedConfig ?. project ) ;
98
134
99
135
if ( ! userData . success ) {
100
136
loadingSpinner . stop ( "Error getting your account details" ) ;
@@ -109,11 +145,21 @@ export async function whoAmI(
109
145
loadingSpinner . stop ( "Retrieved your account details" ) ;
110
146
note (
111
147
`User ID: ${ userData . data . userId }
112
- Email: ${ userData . data . email }
113
- URL: ${ chalkLink ( authentication . auth . apiUrl ) }
114
- ` ,
148
+ Email: ${ userData . data . email }
149
+ URL: ${ chalkLink ( authentication . auth . apiUrl ) } ` ,
115
150
`Account details [${ authentication . profile } ]`
116
151
) ;
152
+
153
+ const { project } = userData . data ;
154
+
155
+ if ( project ) {
156
+ note (
157
+ `Name: ${ project . name }
158
+ Org: ${ project . orgTitle }
159
+ URL: ${ chalkLink ( project . url ) } ` ,
160
+ `Project details [${ resolvedConfig ?. project } ]`
161
+ ) ;
162
+ }
117
163
} else {
118
164
! silent && loadingSpinner . stop ( `Retrieved your account details for ${ userData . data . email } ` ) ;
119
165
}
0 commit comments