@@ -11,7 +11,7 @@ import confirm from '@inquirer/confirm';
11
11
import input from '@inquirer/input' ;
12
12
import select , { Separator } from '@inquirer/select' ;
13
13
import { type Config , defaultConfigPath , readConfig , writeConfig } from './config.js' ;
14
- import { link , pull , push } from './methods.js' ;
14
+ import { link , type LinkOptions , pull , push } from './methods.js' ;
15
15
16
16
/**
17
17
* Global configuration option for the root Commander Command.
@@ -164,15 +164,9 @@ function linkCmd() {
164
164
. action ( async ( paths , _options , command ) => {
165
165
const optsWithGlobals = command . optsWithGlobals < CommonOptions > ( ) ;
166
166
const client = await createClient ( optsWithGlobals ) ;
167
- const linkCache = { } ;
168
-
169
- for ( const path of paths ) {
170
- const existingFile = await readFile ( path , { encoding : 'utf8' } ) ;
171
167
172
- const linkedDiagram = await link ( existingFile , client , {
173
- cache : linkCache ,
174
- title : path ,
175
- async getProjectId ( cache , documentTitle ) {
168
+ // Ask the user which project they want to upload each diagram to
169
+ const getProjectId : LinkOptions [ 'getProjectId' ] = async ( cache , documentTitle ) => {
176
170
if ( cache . previousSelectedProjectId !== undefined ) {
177
171
if ( cache . usePreviousSelectedProjectId === undefined ) {
178
172
cache . usePreviousSelectedProjectId = confirm ( {
@@ -204,7 +198,17 @@ function linkCmd() {
204
198
cache . previousSelectedProjectId = projectId ;
205
199
206
200
return projectId ;
207
- } ,
201
+ } ;
202
+
203
+ const linkCache = { } ;
204
+
205
+ for ( const path of paths ) {
206
+ const existingFile = await readFile ( path , { encoding : 'utf8' } ) ;
207
+
208
+ const linkedDiagram = await link ( existingFile , client , {
209
+ cache : linkCache ,
210
+ title : path ,
211
+ getProjectId,
208
212
} ) ;
209
213
210
214
await writeFile ( path , linkedDiagram , { encoding : 'utf8' } ) ;
0 commit comments