@@ -141,6 +141,18 @@ async function selectOrCreateRemoteAppToLinkTo(options: LinkOptions): Promise<{
141141 }
142142 }
143143
144+ // NEW: if a specific config file was requested and it already knows its client_id,
145+ // try to resolve the remote app from that config and skip interactive selection.
146+ const remoteAppFromConfig = await tryGetRemoteAppFromExistingConfig ( options )
147+ if ( remoteAppFromConfig ) {
148+ return {
149+ remoteApp : remoteAppFromConfig ,
150+ appDirectory,
151+ developerPlatformClient : remoteAppFromConfig . developerPlatformClient ,
152+ }
153+ }
154+
155+ // Existing behavior: prompt to fetch or create an app
144156 const remoteApp = await fetchOrCreateOrganizationApp ( { ...creationOptions , directory : appDirectory } )
145157
146158 const developerPlatformClient = remoteApp . developerPlatformClient
@@ -189,6 +201,34 @@ async function getAppCreationDefaultsFromLocalApp(options: LinkOptions): Promise
189201 }
190202}
191203
204+ async function tryGetRemoteAppFromExistingConfig (
205+ options : LinkOptions ,
206+ ) : Promise < OrganizationApp | undefined > {
207+ if ( ! options . configName ) return undefined
208+
209+ try {
210+ const app = await loadApp ( {
211+ specifications : await loadLocalExtensionsSpecifications ( ) ,
212+ directory : options . directory ,
213+ mode : 'report' ,
214+ userProvidedConfigName : options . configName ,
215+ remoteFlags : undefined ,
216+ } )
217+
218+ const configuration = app . configuration
219+
220+ if ( ! isCurrentAppSchema ( configuration ) || ! configuration . client_id ) {
221+ return undefined
222+ }
223+
224+ const remoteApp = await appFromIdentifiers ( { apiKey : configuration . client_id } )
225+ return remoteApp ?? undefined
226+ } catch {
227+ return undefined
228+ }
229+ }
230+
231+
192232type LocalAppOptions =
193233 | {
194234 state : 'legacy'
0 commit comments