From fe5561df50ba591fa797ae0df7eff211b5dd65e2 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 19 Sep 2019 08:41:00 +0200 Subject: [PATCH] main: Group cli options logically With the API server socket option, we will be able to support a model where the user can start cloud-hypervisor with no options or an alternative API server socket path. In this case, we don't want to try to start a new guest VM, and for that we need to know if the user has set any VM configuration at all. Grouping all VM configuration specific options together is one way to be able to know about it. If the user has not set any VM configuration, we only start the API server. If it has set anything, we will verify that the overall configuration is valid and will implicitly convert that configuration into a request to the API server. Signed-off-by: Samuel Ortiz --- src/main.rs | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 23bb92404..59eb0985f 100755 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ extern crate vmm_sys_util; #[macro_use(crate_version, crate_authors)] extern crate clap; -use clap::{App, Arg}; +use clap::{App, Arg, ArgGroup}; use libc::EFD_NONBLOCK; use log::LevelFilter; use std::process; @@ -67,11 +67,14 @@ fn main() { .version(crate_version!()) .author(crate_authors!()) .about("Launch a cloud-hypervisor VMM.") + .group(ArgGroup::with_name("vm-config").multiple(true)) + .group(ArgGroup::with_name("vmm-config").multiple(true)) .arg( Arg::with_name("cpus") .long("cpus") .help("Number of virtual CPUs") - .default_value(config::DEFAULT_VCPUS), + .default_value(config::DEFAULT_VCPUS) + .group("vm-config"), ) .arg( Arg::with_name("memory") @@ -80,26 +83,30 @@ fn main() { "Memory parameters \"size=,\ file=\"", ) - .default_value(config::DEFAULT_MEMORY), + .default_value(config::DEFAULT_MEMORY) + .group("vm-config"), ) .arg( Arg::with_name("kernel") .long("kernel") .help("Path to kernel image (vmlinux)") - .takes_value(true), + .takes_value(true) + .group("vm-config"), ) .arg( Arg::with_name("cmdline") .long("cmdline") .help("Kernel command line") - .takes_value(true), + .takes_value(true) + .group("vm-config"), ) .arg( Arg::with_name("disk") .long("disk") .help("Path to VM disk image") .takes_value(true) - .min_values(1), + .min_values(1) + .group("vm-config"), ) .arg( Arg::with_name("net") @@ -109,13 +116,15 @@ fn main() { ip=,mask=,mac=\"", ) .takes_value(true) - .min_values(1), + .min_values(1) + .group("vm-config"), ) .arg( Arg::with_name("rng") .long("rng") .help("Path to entropy source") - .default_value(config::DEFAULT_RNG_SOURCE), + .default_value(config::DEFAULT_RNG_SOURCE) + .group("vm-config"), ) .arg( Arg::with_name("fs") @@ -127,7 +136,8 @@ fn main() { cache_size=\"", ) .takes_value(true) - .min_values(1), + .min_values(1) + .group("vm-config"), ) .arg( Arg::with_name("pmem") @@ -137,26 +147,30 @@ fn main() { size=\"", ) .takes_value(true) - .min_values(1), + .min_values(1) + .group("vm-config"), ) .arg( Arg::with_name("serial") .long("serial") .help("Control serial port: off|null|tty|file=/path/to/a/file") - .default_value("null"), + .default_value("null") + .group("vm-config"), ) .arg( Arg::with_name("console") .long("console") .help("Control (virtio) console: off|null|tty|file=/path/to/a/file") - .default_value("tty"), + .default_value("tty") + .group("vm-config"), ) .arg( Arg::with_name("device") .long("device") .help("Direct device assignment parameter") .takes_value(true) - .min_values(1), + .min_values(1) + .group("vm-config"), ) .arg( Arg::with_name("vhost-user-net") @@ -167,7 +181,8 @@ fn main() { queue_size=\"", ) .takes_value(true) - .min_values(1), + .min_values(1) + .group("vm-config"), ) .arg( Arg::with_name("vsock") @@ -177,7 +192,8 @@ fn main() { sock=\"", ) .takes_value(true) - .min_values(1), + .min_values(1) + .group("vm-config"), ) .arg( Arg::with_name("vhost-user-blk") @@ -195,14 +211,16 @@ fn main() { Arg::with_name("v") .short("v") .multiple(true) - .help("Sets the level of debugging output"), + .help("Sets the level of debugging output") + .group("vmm-config"), ) .arg( Arg::with_name("log-file") .long("log-file") .help("Log file. Standard error is used if not specified") .takes_value(true) - .min_values(1), + .min_values(1) + .group("vmm-config"), ) .get_matches();