mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
vhost_user_blk: switch to clap
Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@intel.com>
This commit is contained in:
parent
627a1456a7
commit
f160ba41b5
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2309,8 +2309,8 @@ dependencies = [
|
||||
name = "vhost_user_block"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"argh",
|
||||
"block",
|
||||
"clap",
|
||||
"env_logger",
|
||||
"epoll",
|
||||
"libc",
|
||||
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||
build = "../build.rs"
|
||||
|
||||
[dependencies]
|
||||
argh = "0.1.9"
|
||||
clap = { version = "4.3.11", features = ["wrap_help","cargo"] }
|
||||
block = { path = "../block" }
|
||||
env_logger = "0.10.0"
|
||||
epoll = "4.3.3"
|
||||
|
@ -74,6 +74,11 @@ enum Error {
|
||||
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 {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "vhost_user_block_error: {self:?}")
|
||||
|
@ -10,36 +10,25 @@
|
||||
|
||||
extern crate vhost_user_block;
|
||||
|
||||
use argh::FromArgs;
|
||||
use clap::{Arg, Command};
|
||||
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() {
|
||||
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 {
|
||||
println!("{} {}", env!("CARGO_BIN_NAME"), env!("BUILD_VERSION"));
|
||||
return;
|
||||
}
|
||||
|
||||
if toplevel.backend_command.is_none() {
|
||||
println!("Please specify --block-backend");
|
||||
std::process::exit(1)
|
||||
}
|
||||
|
||||
start_block_backend(&toplevel.backend_command.unwrap());
|
||||
let backend_command = cmd_arguments.get_one::<String>("block-backend").unwrap();
|
||||
start_block_backend(backend_command);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user