11import { spawn } from 'node:child_process'
22import { createInterface } from 'node:readline/promises'
33import { Command } from 'commander'
4+ import { printLine } from '#cli/output/io'
45import { styles } from '#cli/output/presentation'
56import {
67 buildApprovalUrl ,
@@ -212,9 +213,9 @@ async function chooseWorkspace(client: Pick<SimClient, 'request'>): Promise<Sele
212213 )
213214 }
214215
215- console . log ( '\nAvailable workspaces:' )
216+ printLine ( '\nAvailable workspaces:' )
216217 for ( const [ index , workspace ] of workspaces . entries ( ) ) {
217- console . log ( ` ${ index + 1 } ) ${ safeOneLine ( workspace . name ) } (${ workspace . id } )` )
218+ printLine ( ` ${ index + 1 } ) ${ safeOneLine ( workspace . name ) } (${ workspace . id } )` )
218219 }
219220
220221 const prompt = createInterface ( { input : process . stdin , output : process . stderr } )
@@ -257,12 +258,10 @@ function addProfileCommand(): Command {
257258 workspace : normalizeWorkspaceId ( workspace . id , 'the workspace response' ) ,
258259 } )
259260
260- console . log (
261- styles ( ) . green ( `✓ Added profile "${ safeOneLine ( profileName ) } " in ${ configPath ( ) } ` )
262- )
263- console . log ( ` Workspace: ${ safeOneLine ( workspace . name ) } (${ workspace . id } )` )
264- console . log ( ` Authentication: ${ safeOneLine ( authProfile ) } ` )
265- console . log ( styles ( ) . dim ( ` Try: sim --profile ${ safeOneLine ( profileName ) } whoami` ) )
261+ printLine ( styles ( ) . green ( `✓ Added profile "${ safeOneLine ( profileName ) } " in ${ configPath ( ) } ` ) )
262+ printLine ( ` Workspace: ${ safeOneLine ( workspace . name ) } (${ workspace . id } )` )
263+ printLine ( ` Authentication: ${ safeOneLine ( authProfile ) } ` )
264+ printLine ( styles ( ) . dim ( ` Try: sim --profile ${ safeOneLine ( profileName ) } whoami` ) )
266265 } )
267266}
268267
@@ -294,7 +293,7 @@ export function loginCommand(): Command {
294293 if ( readCredentialsProfile ( profile . name ) . api_key && ! options . yes ) {
295294 const confirmed = await confirmProfileOverwrite ( profile . name )
296295 if ( ! confirmed ) {
297- console . log ( styles ( ) . dim ( 'Login cancelled; the existing profile was not changed.' ) )
296+ printLine ( styles ( ) . dim ( 'Login cancelled; the existing profile was not changed.' ) )
298297 return
299298 }
300299 }
@@ -307,17 +306,17 @@ export function loginCommand(): Command {
307306 profile . workspaceId ?? undefined
308307 )
309308
310- console . log (
309+ printLine (
311310 `Signing in to ${ styles ( ) . bold ( profile . endpoint ) } as profile ${ styles ( ) . bold ( safeOneLine ( profile . name ) ) } `
312311 )
313- console . log ( `\nPairing code: ${ styles ( ) . bold ( auth . pairing ) } ` )
314- console . log (
312+ printLine ( `\nPairing code: ${ styles ( ) . bold ( auth . pairing ) } ` )
313+ printLine (
315314 styles ( ) . dim ( 'Confirm this code matches what the browser shows before approving.\n' )
316315 )
317- console . log ( url )
316+ printLine ( url )
318317
319318 if ( options . browser ) openBrowser ( url )
320- console . log ( styles ( ) . dim ( '\nWaiting for approval…' ) )
319+ printLine ( styles ( ) . dim ( '\nWaiting for approval…' ) )
321320
322321 const key = await pollForKey ( profile . endpoint , auth )
323322
@@ -360,19 +359,17 @@ export function loginCommand(): Command {
360359 writeConfigProfile ( profile . name , settings )
361360 writeCredentialsProfile ( profile . name , key . apiKey )
362361
363- console . log ( styles ( ) . green ( `\n✓ Logged in. Key stored in ${ credentialsPath ( ) } ` ) )
362+ printLine ( styles ( ) . green ( `\n✓ Logged in. Key stored in ${ credentialsPath ( ) } ` ) )
364363 if ( key . workspaceBound && key . workspaceId ) {
365- console . log (
366- styles ( ) . dim ( ` Workspace-scoped key — it can only reach ${ key . workspaceId } .` )
367- )
364+ printLine ( styles ( ) . dim ( ` Workspace-scoped key — it can only reach ${ key . workspaceId } .` ) )
368365 } else if ( key . workspaceId ) {
369- console . log (
366+ printLine (
370367 styles ( ) . dim (
371368 ` Personal key, defaulting to ${ key . workspaceId } . Override per command with --workspace.`
372369 )
373370 )
374371 } else {
375- console . log (
372+ printLine (
376373 styles ( ) . dim (
377374 ' Personal key with no default workspace. Set one with: sim configure --set-workspace <id>'
378375 )
@@ -398,10 +395,10 @@ export function logoutCommand(): Command {
398395 }
399396 const removed = deleteProfile ( profileName )
400397 if ( ! removed . config && ! removed . credentials ) {
401- console . log ( styles ( ) . dim ( `Nothing stored for profile "${ safeOneLine ( profileName ) } ".` ) )
398+ printLine ( styles ( ) . dim ( `Nothing stored for profile "${ safeOneLine ( profileName ) } ".` ) )
402399 return
403400 }
404- console . log ( styles ( ) . green ( `✓ Removed profile "${ safeOneLine ( profileName ) } ".` ) )
401+ printLine ( styles ( ) . green ( `✓ Removed profile "${ safeOneLine ( profileName ) } ".` ) )
405402 return
406403 }
407404
@@ -415,17 +412,17 @@ export function logoutCommand(): Command {
415412 }
416413
417414 if ( ! readCredentialsProfile ( profile . name ) . api_key ) {
418- console . log ( styles ( ) . dim ( `No stored key for profile "${ safeOneLine ( profile . name ) } ".` ) )
415+ printLine ( styles ( ) . dim ( `No stored key for profile "${ safeOneLine ( profile . name ) } ".` ) )
419416 return
420417 }
421418
422419 writeCredentialsProfile ( profile . name , null )
423- console . log (
420+ printLine (
424421 styles ( ) . green ( `✓ Removed the stored key for profile "${ safeOneLine ( profile . name ) } ".` )
425422 )
426423 // The key still exists server-side; leaving that unsaid invites the
427424 // assumption that logging out revoked it.
428- console . log (
425+ printLine (
429426 styles ( ) . dim ( ' The key itself is still active — revoke it in Settings → Sim API keys.' )
430427 )
431428 } )
@@ -759,7 +756,7 @@ export function profilesCommand(): Command {
759756 if ( rows . length === 0 ) {
760757 // The prose belongs to the human formats; a script asking for json must
761758 // get an empty list, not a sentence it cannot parse.
762- if ( output === 'table' ) console . log ( styles ( ) . dim ( 'No profiles yet. Run: sim login' ) )
759+ if ( output === 'table' ) printLine ( styles ( ) . dim ( 'No profiles yet. Run: sim login' ) )
763760 else printList ( output , rows , PROFILE_COLUMNS )
764761 return
765762 }
0 commit comments