@@ -6,7 +6,7 @@ use std::{path::Path, time::Duration};
66
77use anyhow:: { anyhow, Context , Result } ;
88use app:: App ;
9- use clap:: Parser ;
9+ use clap:: { Args as ClapArgs , Parser , Subcommand } ;
1010use config:: Config ;
1111use guest_api_service:: GuestApiHandler ;
1212use host_api_service:: HostApiHandler ;
@@ -47,13 +47,28 @@ struct Args {
4747 /// Path to the configuration file
4848 #[ arg( short, long) ]
4949 config : Option < String > ,
50- /// One-shot mode: setup VM and execute QEMU command from VM configuration file
51- #[ arg( long) ]
52- one_shot : Option < String > ,
50+ /// Subcommand to run
51+ #[ command( subcommand) ]
52+ command : Option < Command > ,
53+ }
54+
55+ #[ derive( Default , Subcommand ) ]
56+ enum Command {
57+ /// Start the VMM server (default mode)
58+ #[ default]
59+ Serve ,
60+ /// One-shot VM execution mode for debugging
61+ Run ( RunArgs ) ,
62+ }
63+
64+ #[ derive( ClapArgs ) ]
65+ struct RunArgs {
66+ /// VM configuration file path
67+ vm_config : String ,
5368 /// Working directory for one-shot mode (default: create in current directory)
5469 #[ arg( long) ]
5570 workdir : Option < String > ,
56- /// Dry run: only output QEMU command without executing (use with --one-shot)
71+ /// Dry run: only output QEMU command without executing
5772 #[ arg( long) ]
5873 dry_run : bool ,
5974}
@@ -145,12 +160,23 @@ async fn main() -> Result<()> {
145160 let figment = config:: load_config_figment ( args. config . as_deref ( ) ) ;
146161 let config = Config :: extract_or_default ( & figment) ?. abs_path ( ) ?;
147162
148- // Handle one-shot mode
149- if let Some ( vm_config_path) = args. one_shot {
150- return one_shot:: run_one_shot ( & vm_config_path, config, args. workdir , args. dry_run ) . await ;
163+ // Handle commands
164+ match args. command {
165+ Some ( Command :: Run ( run_args) ) => {
166+ // One-shot VM execution mode
167+ return one_shot:: run_one_shot (
168+ & run_args. vm_config ,
169+ config,
170+ run_args. workdir ,
171+ run_args. dry_run ,
172+ )
173+ . await ;
174+ }
175+ Some ( Command :: Serve ) | None => {
176+ // Default server mode - continue to main server logic
177+ }
151178 }
152179
153-
154180 let api_auth = ApiToken :: new ( config. auth . tokens . clone ( ) , config. auth . enabled ) ;
155181 let supervisor = {
156182 let cfg = & config. supervisor ;
0 commit comments