From b8172408f824fd6e7301a4d837183e755ff0649d Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Fri, 13 Jan 2023 00:57:20 +0000 Subject: [PATCH] vhost_user_net: add --version Signed-off-by: Wei Liu --- vhost_user_net/Cargo.toml | 1 + vhost_user_net/src/main.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/vhost_user_net/Cargo.toml b/vhost_user_net/Cargo.toml index 2d835ae48..1c621e0b7 100644 --- a/vhost_user_net/Cargo.toml +++ b/vhost_user_net/Cargo.toml @@ -3,6 +3,7 @@ name = "vhost_user_net" version = "0.1.0" authors = ["The Cloud Hypervisor Authors"] edition = "2021" +build = "../build.rs" [dependencies] argh = "0.1.9" diff --git a/vhost_user_net/src/main.rs b/vhost_user_net/src/main.rs index e7bc81336..d00cfeff1 100644 --- a/vhost_user_net/src/main.rs +++ b/vhost_user_net/src/main.rs @@ -15,7 +15,11 @@ struct TopLevel { #[argh(option, long = "net-backend")] /// vhost-user-net backend parameters /// ip=,mask=,socket=,client=on|off,num_queues=,queue_size=,tap= - backend_command: String, + backend_command: Option, + + #[argh(switch, short = 'V', long = "version")] + /// print version information + version: bool, } fn main() { @@ -23,5 +27,15 @@ fn main() { let toplevel: TopLevel = argh::from_env(); - start_net_backend(&toplevel.backend_command); + if toplevel.version { + println!("{} {}", env!("CARGO_BIN_NAME"), env!("BUILT_VERSION")); + return; + } + + if toplevel.backend_command.is_none() { + println!("Please specify --net-backend"); + std::process::exit(1) + } + + start_net_backend(&toplevel.backend_command.unwrap()); }