@@ -81,35 +81,39 @@ export abstract class GlobalCommand<C extends GlobalCommandDefinition> extends B
8181 }
8282
8383 protected async getAuthenticatedClient ( credentials : Partial < YargsConfig < typeof config . schemas . credentials > > ) {
84- const cache = this . globalCache
85-
86- let token : string | undefined
87- let workspaceId : string | undefined
88- let apiUrl : string | undefined
84+ try {
85+ const cache = this . globalCache
86+
87+ let token : string | undefined
88+ let workspaceId : string | undefined
89+ let apiUrl : string | undefined
90+
91+ if ( this . argv . profile ) {
92+ if ( credentials . token || credentials . workspaceId || credentials . apiUrl ) {
93+ this . logger . warn (
94+ 'You are currently using credential command line arguments or environment variables as well as a profile. Your profile has overwritten the variables'
95+ )
96+ }
97+ ; ( { token, workspaceId, apiUrl } = await this . readProfileFromFS ( this . argv . profile ) )
98+ this . logger . log ( `Using profile "${ this . argv . profile } "` , { prefix : '👤' } )
99+ } else {
100+ token = credentials . token ?? ( await cache . get ( 'token' ) )
101+ workspaceId = credentials . workspaceId ?? ( await cache . get ( 'workspaceId' ) )
102+ apiUrl = credentials . apiUrl ?? ( await cache . get ( 'apiUrl' ) )
103+ }
89104
90- if ( this . argv . profile ) {
91- if ( credentials . token || credentials . workspaceId || credentials . apiUrl ) {
92- this . logger . warn (
93- 'You are currently using credential command line arguments or environment variables as well as a profile. Your profile has overwritten the variables'
94- )
105+ if ( ! ( token && workspaceId && apiUrl ) ) {
106+ return null
95107 }
96- ; ( { token, workspaceId, apiUrl } = await this . readProfileFromFS ( this . argv . profile ) )
97- this . logger . log ( `Using profile "${ this . argv . profile } "` , { prefix : '👤' } )
98- } else {
99- token = credentials . token ?? ( await cache . get ( 'token' ) )
100- workspaceId = credentials . workspaceId ?? ( await cache . get ( 'workspaceId' ) )
101- apiUrl = credentials . apiUrl ?? ( await cache . get ( 'apiUrl' ) )
102- }
103108
104- if ( ! ( token && workspaceId && apiUrl ) ) {
105- return null
106- }
109+ if ( apiUrl !== consts . defaultBotpressApiUrl ) {
110+ this . logger . log ( `Using custom url ${ apiUrl } ` , { prefix : '🔗' } )
111+ }
107112
108- if ( apiUrl !== consts . defaultBotpressApiUrl ) {
109- this . logger . log ( `Using custom url ${ apiUrl } ` , { prefix : '🔗' } )
113+ return this . api . newClient ( { apiUrl, token, workspaceId } , this . logger )
114+ } catch ( thrown ) {
115+ throw errors . BotpressCLIError . wrap ( thrown , 'failed to create authenticated client' )
110116 }
111-
112- return this . api . newClient ( { apiUrl, token, workspaceId } , this . logger )
113117 }
114118
115119 protected async readProfileFromFS ( profile : string ) : Promise < ProfileCredentials > {
0 commit comments