@@ -12,36 +12,50 @@ export enum ConnectCommand {
1212
1313const CommandInfo = {
1414 [ ConnectCommand . TERMINAL ] : {
15- args : [ ] ,
15+ command : ( ) => [ ] ,
16+ requiresDocumentId : false ,
1617 } ,
1718 [ ConnectCommand . APPLY ] : {
18- args : [ '-c' , 'codify apply' ]
19+ command : ( args ) => [ '-c' , `codify apply ${ args } ` ] ,
20+ requiresDocumentId : true ,
21+ } ,
22+ [ ConnectCommand . PLAN ] : {
23+ command : ( args ) => [ '-c' , `codify plan ${ args } ` ] ,
24+ requiresDocumentId : true ,
25+ } ,
26+ [ ConnectCommand . IMPORT ] : {
27+ command : ( args ) => [ '-c' , `codify import ${ args } ` ] ,
28+ requiresDocumentId : true ,
1929 }
20-
2130}
2231
2332export function createCommandHandler ( command : ConnectCommand ) : Router {
24- // if (!Object.values(ConnectCommand).includes(command)) {
25- // throw new Error(`Unknown command ${command}. Please check code`);
26- // }
27- //
28- // const commandInfo = CommandInfo[command];
29- // if (!commandInfo) {
30- // throw new Error(`Command info not provided for ${command}. Please check code`);
31- // }
33+ if ( ! Object . values ( ConnectCommand ) . includes ( command ) ) {
34+ throw new Error ( `Unknown command ${ command } . Please check code` ) ;
35+ }
36+
37+ const commandInfo = CommandInfo [ command ] ;
38+ if ( ! commandInfo ) {
39+ throw new Error ( `Command info not provided for ${ command } . Please check code` ) ;
40+ }
3241
3342 const router = Router ( {
3443 mergeParams : true ,
3544 } ) ;
3645
3746 router . post ( '/:sessionId/start' , async ( req , res ) => {
3847 const { sessionId } = req . params ;
48+ const { documentId } = req . body ;
3949 console . log ( `Received request to ${ command } , sessionId: ${ sessionId } ` )
4050
4151 if ( ! sessionId ) {
4252 return res . status ( 400 ) . json ( { error : 'SessionId must be provided' } ) ;
4353 }
4454
55+ if ( commandInfo . requiresDocumentId && ! documentId ) {
56+ return res . status ( 400 ) . json ( { error : 'Document id must be provided' } ) ;
57+ }
58+
4559 const manager = SocketServer . get ( ) ;
4660 const session = manager . getSession ( sessionId ) ;
4761 if ( ! session ) {
@@ -57,7 +71,8 @@ export function createCommandHandler(command: ConnectCommand): Router {
5771 return res . status ( 304 ) . json ( { status : 'Already started' } )
5872 }
5973
60- const pty = spawn ( 'zsh' , [ ] , {
74+ console . log ( 'Running command:' , commandInfo . command ( documentId ) )
75+ const pty = spawn ( 'zsh' , commandInfo . command ( documentId ) , {
6176 name : 'xterm-color' ,
6277 cols : 80 ,
6378 rows : 30 ,
0 commit comments