@@ -107,6 +107,7 @@ class GrainCommand extends commander.Command {
107107 ) ;
108108 cmd . forwardOption ( "--import-memory" , "import the memory from `env.memory`" ) ;
109109 cmd . option ( "--dir <dir...>" , "directory to preopen" ) ;
110+ cmd . option ( "--env <env...>" , "WASI environment variables" ) ;
110111 cmd . forwardOption (
111112 "--compilation-mode <mode>" ,
112113 "compilation mode (advanced use only)"
@@ -164,6 +165,13 @@ class GrainCommand extends commander.Command {
164165 }
165166}
166167
168+ let endOptsI = process . argv . findIndex ( ( x ) => x === "--" ) ;
169+ if ( endOptsI === - 1 ) {
170+ endOptsI = Infinity ;
171+ }
172+ const argsToProcess = process . argv . slice ( 0 , endOptsI ) ;
173+ const unprocessedArgs = process . argv . slice ( endOptsI + 1 ) ;
174+
167175const program = new GrainCommand ( ) ;
168176
169177program
@@ -178,11 +186,8 @@ program
178186 . forwardOption ( "-o <filename>" , "output filename" )
179187 . action ( function ( file , options , program ) {
180188 exec . grainc ( file , options , program ) ;
181- if ( options . o ) {
182- exec . grainrun ( options . o , options , program ) ;
183- } else {
184- exec . grainrun ( file . replace ( / \. g r $ / , ".gr.wasm" ) , options , program ) ;
185- }
189+ const outFile = options . o ?? file . replace ( / \. g r $ / , ".gr.wasm" ) ;
190+ exec . grainrun ( unprocessedArgs , outFile , options , program ) ;
186191 } ) ;
187192
188193program
@@ -195,7 +200,7 @@ program
195200program
196201 . command ( "run <file>" )
197202 . description ( "run a wasm file via grain's WASI runner" )
198- . action ( exec . grainrun ) ;
203+ . action ( ( ... args ) => exec . grainrun ( unprocessedArgs , ... args ) ) ;
199204
200205program
201206 . command ( "lsp" )
@@ -218,4 +223,4 @@ program
218223 . forwardOption ( "-o <file|dir>" , "output file or directory" )
219224 . action ( exec . grainformat ) ;
220225
221- program . parse ( process . argv ) ;
226+ program . parse ( argsToProcess ) ;
0 commit comments