@@ -10,6 +10,39 @@ import { Global } from "../../global"
1010import { Plugin } from "../../plugin"
1111import { Instance } from "../../project/instance"
1212
13+ // Simple command parser that handles quoted strings
14+ function parseCommand ( input : string ) : string [ ] {
15+ const args : string [ ] = [ ]
16+ let current = ""
17+ let inQuotes = false
18+ let quoteChar = ""
19+
20+ for ( let i = 0 ; i < input . length ; i ++ ) {
21+ const char = input [ i ]
22+
23+ if ( ! inQuotes && ( char === '"' || char === "'" ) ) {
24+ inQuotes = true
25+ quoteChar = char
26+ } else if ( inQuotes && char === quoteChar ) {
27+ inQuotes = false
28+ quoteChar = ""
29+ } else if ( ! inQuotes && char === " " ) {
30+ if ( current ) {
31+ args . push ( current )
32+ current = ""
33+ }
34+ } else {
35+ current += char
36+ }
37+ }
38+
39+ if ( current ) {
40+ args . push ( current )
41+ }
42+
43+ return args . filter ( ( arg ) => arg . length > 0 )
44+ }
45+
1346export const AuthCommand = cmd ( {
1447 command : "auth" ,
1548 describe : "manage credentials" ,
@@ -253,16 +286,46 @@ export const AuthLoginCommand = cmd({
253286 prompts . log . info ( "You can create an api key at https://vercel.link/ai-gateway-token" )
254287 }
255288
256- const key = await prompts . password ( {
257- message : "Enter your API key" ,
289+ const authMethod = await prompts . select ( {
290+ message : "How would you like to provide the API key?" ,
291+ options : [
292+ { label : "Enter API key directly" , value : "direct" } ,
293+ { label : "Run a command to get the API key" , value : "command" } ,
294+ ] ,
295+ } )
296+ if ( prompts . isCancel ( authMethod ) ) throw new UI . CancelledError ( )
297+
298+ if ( authMethod === "direct" ) {
299+ const key = await prompts . password ( {
300+ message : "Enter your API key" ,
301+ validate : ( x ) => ( x && x . length > 0 ? undefined : "Required" ) ,
302+ } )
303+ if ( prompts . isCancel ( key ) ) throw new UI . CancelledError ( )
304+ await Auth . set ( provider , {
305+ type : "api" ,
306+ key,
307+ } )
308+ prompts . outro ( "Done" )
309+ return
310+ }
311+
312+ const commandInput = await prompts . text ( {
313+ message : "Enter the command to run (e.g., 'op read op://vault/item')" ,
258314 validate : ( x ) => ( x && x . length > 0 ? undefined : "Required" ) ,
259315 } )
260- if ( prompts . isCancel ( key ) ) throw new UI . CancelledError ( )
316+ if ( prompts . isCancel ( commandInput ) ) throw new UI . CancelledError ( )
317+
318+ // Parse command string into array with proper quote handling
319+ const command = parseCommand ( commandInput )
320+ if ( command . length === 0 ) {
321+ prompts . log . error ( "Invalid command" )
322+ return
323+ }
324+
261325 await Auth . set ( provider , {
262- type : "api " ,
263- key ,
326+ type : "cmd " ,
327+ command ,
264328 } )
265-
266329 prompts . outro ( "Done" )
267330 } )
268331 } ,
0 commit comments