vhost_user_blk: switch to clap

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@intel.com>
This commit is contained in:
Ravi kumar Veeramally 2023-09-21 18:35:44 +03:00 committed by Bo Chen
parent 627a1456a7
commit f160ba41b5
4 changed files with 22 additions and 28 deletions

2
Cargo.lock generated
View File

@ -2309,8 +2309,8 @@ dependencies = [
name = "vhost_user_block" name = "vhost_user_block"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"argh",
"block", "block",
"clap",
"env_logger", "env_logger",
"epoll", "epoll",
"libc", "libc",

View File

@ -6,7 +6,7 @@ edition = "2021"
build = "../build.rs" build = "../build.rs"
[dependencies] [dependencies]
argh = "0.1.9" clap = { version = "4.3.11", features = ["wrap_help","cargo"] }
block = { path = "../block" } block = { path = "../block" }
env_logger = "0.10.0" env_logger = "0.10.0"
epoll = "4.3.3" epoll = "4.3.3"

View File

@ -74,6 +74,11 @@ enum Error {
SocketParameterMissing, SocketParameterMissing,
} }
pub const SYNTAX: &str = "vhost-user-block backend parameters \
\"path=<image_path>,socket=<socket_path>,num_queues=<number_of_queues>,\
queue_size=<size_of_each_queue>,readonly=true|false,direct=true|false,\
poll_queue=true|false\"";
impl fmt::Display for Error { impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "vhost_user_block_error: {self:?}") write!(f, "vhost_user_block_error: {self:?}")

View File

@ -10,36 +10,25 @@
extern crate vhost_user_block; extern crate vhost_user_block;
use argh::FromArgs; use clap::{Arg, Command};
use vhost_user_block::start_block_backend; use vhost_user_block::start_block_backend;
#[derive(FromArgs)]
/// Launch a vhost-user-blk backend.
struct TopLevel {
#[argh(option, long = "block-backend")]
/// vhost-user-block backend parameters
/// path=<image_path>,socket=<socket_path>,num_queues=<number_of_queues>,queue_size=<size_of_each_queue>,readonly=true|false,direct=true|false,poll_queue=true|false
backend_command: Option<String>,
#[argh(switch, short = 'V', long = "version")]
/// print version information
version: bool,
}
fn main() { fn main() {
env_logger::init(); env_logger::init();
let toplevel: TopLevel = argh::from_env(); let cmd_arguments = Command::new("vhost-user-blk backend")
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about("Launch a vhost-user-blk backend.")
.arg(
Arg::new("block-backend")
.long("block-backend")
.help(vhost_user_block::SYNTAX)
.num_args(1)
.required(true),
)
.get_matches();
if toplevel.version { let backend_command = cmd_arguments.get_one::<String>("block-backend").unwrap();
println!("{} {}", env!("CARGO_BIN_NAME"), env!("BUILD_VERSION")); start_block_backend(backend_command);
return;
}
if toplevel.backend_command.is_none() {
println!("Please specify --block-backend");
std::process::exit(1)
}
start_block_backend(&toplevel.backend_command.unwrap());
} }