make args simply

This commit is contained in:
Masato Imai
2022-08-23 10:17:45 +09:00
parent 49d6e03e54
commit c1ffb262ef
2 changed files with 10 additions and 19 deletions

View File

@ -1,17 +1,14 @@
use std::path::PathBuf;
use clap::Parser; use clap::Parser;
use clap::ValueHint;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)] #[clap(author, version, about, long_about = None)]
pub struct Args { pub struct Args {
#[clap(short, long, value_parser)]
pub mode: String,
#[clap(short, long, value_parser)]
pub file: Option<String>,
#[clap(short, long, value_parser)]
pub ip: Option<String>,
#[clap(short, long, value_parser)] #[clap(short, long, value_parser)]
pub port: Option<u16>, pub port: Option<u16>,
#[clap(name = "FILE", value_hint = ValueHint::AnyPath)]
pub file: Option<PathBuf>,
} }

View File

@ -16,15 +16,9 @@ fn main() {
env_logger::init(); env_logger::init();
let args = Args::parse(); let args = Args::parse();
match &*args.mode { if let Some(_) = args.port {
"server" => { start_server(args);
start_server(args); } else {
} start_client(args);
"client" => {
start_client(args);
}
_ => {
println!("Unknown mode");
}
} }
} }