@@ -12,33 +12,68 @@ pub(crate) use wasm_host::WasmHost;
1212use anyhow:: Result ;
1313use api:: host_api:: repl:: api:: transport;
1414use clap:: Parser ;
15- use cli:: Cli ;
15+ use cli:: { Cli , Commands } ;
1616use helpers:: { StatusHandler , StdoutHandler } ;
1717use std:: io:: Write ;
1818
1919/// Main entry point for the REPL application
2020pub async fn run_async ( ) -> Result < ( ) > {
2121 // Parse command line arguments
2222 let cli = Cli :: parse ( ) ;
23+
24+ // Handle subcommands first
25+ if let Some ( command) = & cli. command {
26+ match command {
27+ Commands :: GenerateCompletions { shell } => {
28+ return handle_generate_completions ( * shell) ;
29+ }
30+ }
31+ }
32+
33+ // For REPL mode, repl_logic is required
34+ let repl_logic = cli
35+ . repl_logic
36+ . ok_or_else ( || anyhow:: anyhow!( "--repl-logic is required when running in REPL mode" ) ) ?;
37+
2338 let debug = cli. debug ;
39+ let plugins = cli. plugins ;
40+ let dir = cli. dir ;
41+ let allow_net = cli. allow_net ;
42+ let allow_read = cli. allow_read ;
43+ let allow_write = cli. allow_write ;
44+ let allow_all = cli. allow_all ;
45+
46+ // Create a new CLI struct for the remaining operations
47+ let repl_cli = Cli {
48+ command : None ,
49+ plugins,
50+ repl_logic : Some ( repl_logic. clone ( ) ) ,
51+ debug,
52+ dir,
53+ allow_net,
54+ allow_read,
55+ allow_write,
56+ allow_all,
57+ } ;
58+
2459 println ! ( "[Host] Starting REPL host..." ) ;
2560
2661 // Create a WASI context for the host
2762 // Binding stdio, args, env, preopened dir ...
28- let wasi_ctx = WasmEngine :: build_wasi_ctx ( & cli ) ?;
63+ let wasi_ctx = WasmEngine :: build_wasi_ctx ( & repl_cli ) ?;
2964
3065 // Create the WebAssembly engine
3166 let engine = WasmEngine :: new ( ) ?;
3267
3368 // Create the host
34- let mut host = WasmHost :: new ( & engine, wasi_ctx, & cli ) ;
69+ let mut host = WasmHost :: new ( & engine, wasi_ctx, & repl_cli ) ;
3570
36- println ! ( "[Host] Loading REPL logic from: {}" , cli . repl_logic) ;
71+ println ! ( "[Host] Loading REPL logic from: {}" , repl_logic) ;
3772 // Override the REPL logic in the binary with the one passed by params
38- host. load_repl_logic ( & engine, & cli . repl_logic ) . await ?;
73+ host. load_repl_logic ( & engine, & repl_logic) . await ?;
3974
4075 // Load plugins
41- for plugin_source in & cli . plugins {
76+ for plugin_source in & repl_cli . plugins {
4277 println ! ( "[Host] Loading plugin: {}" , plugin_source) ;
4378 host. load_plugin ( & engine, plugin_source) . await ?;
4479 }
@@ -216,3 +251,21 @@ pub async fn run_async() -> Result<()> {
216251 }
217252 }
218253}
254+
255+ /// Handle the generate-completions subcommand
256+ fn handle_generate_completions ( shell : cli:: AvailableShells ) -> Result < ( ) > {
257+ use clap:: CommandFactory ;
258+ use clap_complete:: { generate, Shell } ;
259+ use cli:: Cli ;
260+
261+ let mut cmd = Cli :: command ( ) ;
262+ let shell_type = match shell {
263+ cli:: AvailableShells :: Bash => Shell :: Bash ,
264+ cli:: AvailableShells :: Fish => Shell :: Fish ,
265+ cli:: AvailableShells :: Zsh => Shell :: Zsh ,
266+ } ;
267+
268+ generate ( shell_type, & mut cmd, "pluginlab" , & mut std:: io:: stdout ( ) ) ;
269+
270+ Ok ( ( ) )
271+ }
0 commit comments