Skip to content

Commit 1fec560

Browse files
committed
imp: setup optional sub-command run
1 parent f187285 commit 1fec560

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

vmm/src/main.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{path::Path, time::Duration};
66

77
use anyhow::{anyhow, Context, Result};
88
use app::App;
9-
use clap::Parser;
9+
use clap::{Args as ClapArgs, Parser, Subcommand};
1010
use config::Config;
1111
use guest_api_service::GuestApiHandler;
1212
use 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;

vmm/src/one_shot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
use crate::app::{Image, VmConfig, VmWorkDir};
6-
use crate::main_service;
76
use crate::config::Config;
7+
use crate::main_service;
88
use anyhow::{Context, Result};
99

1010
pub async fn run_one_shot(

0 commit comments

Comments
 (0)