@@ -6,44 +6,35 @@ export function execCommand(): Command {
66 return new Command ( 'exec' )
77 . description ( 'Execute a command in a sandbox' )
88 . argument ( '<sandbox_id>' , 'Sandbox ID' )
9- . argument ( '<cmd>' , 'Command to execute (quote if it contains spaces) ' )
10- . option ( '--no-stream' , 'Wait for completion instead of streaming' )
9+ . argument ( '<cmd... >' , 'Command to execute' )
10+ . allowUnknownOption ( true )
1111 . option ( '--json' , 'Output as JSON' )
1212 . action (
1313 async (
1414 sandboxId : string ,
15- cmd : string ,
16- options : { stream : boolean ; json ?: boolean } ,
15+ cmdParts : string [ ] ,
16+ options : { json ?: boolean } ,
1717 ) => {
18+ const cmd = cmdParts . join ( ' ' )
1819 try {
1920 const client = getClient ( )
2021 const sandbox = await client . get ( sandboxId )
22+ const result = await sandbox . exec ( cmd )
2123
22- if ( options . json || ! options . stream ) {
23- const result = await sandbox . exec ( cmd )
24-
25- if ( options . json ) {
26- printJson ( {
27- exec_id : result . execId ,
28- exit_code : result . exitCode ,
29- stdout : result . stdout ,
30- stderr : result . stderr ,
31- duration_ms : result . durationMs ,
32- } )
33- } else {
34- if ( result . stdout ) process . stdout . write ( result . stdout )
35- if ( result . stderr ) process . stderr . write ( result . stderr )
36- }
37-
38- if ( result . exitCode !== 0 ) process . exit ( 1 )
39- } else {
40- const result = await sandbox . exec ( cmd , {
41- onStdout : ( data ) => process . stdout . write ( data ) ,
42- onStderr : ( data ) => process . stderr . write ( data ) ,
24+ if ( options . json ) {
25+ printJson ( {
26+ exec_id : result . execId ,
27+ exit_code : result . exitCode ,
28+ stdout : result . stdout ,
29+ stderr : result . stderr ,
30+ duration_ms : result . durationMs ,
4331 } )
44-
45- if ( result . exitCode !== 0 ) process . exit ( 1 )
32+ } else {
33+ if ( result . stdout ) process . stdout . write ( result . stdout )
34+ if ( result . stderr ) process . stderr . write ( result . stderr )
4635 }
36+
37+ if ( result . exitCode !== 0 ) process . exit ( 1 )
4738 } catch ( err ) {
4839 handleError ( err )
4940 }
0 commit comments