@@ -13,6 +13,9 @@ import {
1313import { z } from "zod" ;
1414import { CliApiClient } from "../apiClient.js" ;
1515import { 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" ;
1619
1720type WhoAmIResult =
1821 | {
@@ -21,20 +24,36 @@ type WhoAmIResult =
2124 userId : string ;
2225 email : string ;
2326 dashboardUrl : string ;
27+ projectUrl ?: string ;
2428 } ;
2529 }
2630 | {
2731 success : false ;
2832 error : string ;
2933 } ;
3034
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+ } ) ;
3240
3341type WhoamiCommandOptions = z . infer < typeof WhoamiCommandOptions > ;
3442
3543export function configureWhoamiCommand ( program : Command ) {
3644 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+ )
3857 ) . action ( async ( options ) => {
3958 await handleTelemetry ( async ( ) => {
4059 await printInitialBanner ( false ) ;
@@ -58,6 +77,23 @@ export async function whoAmI(
5877 intro ( `Displaying your account details [${ options ?. profile ?? "default" } ]` ) ;
5978 }
6079
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+
6197 const loadingSpinner = spinner ( ) ;
6298
6399 if ( ! silent ) {
@@ -94,7 +130,7 @@ export async function whoAmI(
94130 }
95131
96132 const apiClient = new CliApiClient ( authentication . auth . apiUrl , authentication . auth . accessToken ) ;
97- const userData = await apiClient . whoAmI ( ) ;
133+ const userData = await apiClient . whoAmI ( resolvedConfig ?. project ) ;
98134
99135 if ( ! userData . success ) {
100136 loadingSpinner . stop ( "Error getting your account details" ) ;
@@ -109,11 +145,21 @@ export async function whoAmI(
109145 loadingSpinner . stop ( "Retrieved your account details" ) ;
110146 note (
111147 `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 ) } ` ,
115150 `Account details [${ authentication . profile } ]`
116151 ) ;
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+ }
117163 } else {
118164 ! silent && loadingSpinner . stop ( `Retrieved your account details for ${ userData . data . email } ` ) ;
119165 }
0 commit comments