fix: fix client argument parsing
This commit is contained in:
parent
7a6be5e9b5
commit
9060cbd74f
3 changed files with 6 additions and 16 deletions
|
|
@ -62,14 +62,6 @@ impl ClientConfig {
|
|||
pub fn new<T: Iterator<Item = String>>(mut args: T) -> Result<ClientConfig, Box<dyn Error>> {
|
||||
let mut config = ClientConfig::default();
|
||||
|
||||
args.next();
|
||||
|
||||
if let Some(file_name) = args.next() {
|
||||
config.filename = PathBuf::from(file_name);
|
||||
} else {
|
||||
return Err("Missing file to upload or download".into());
|
||||
}
|
||||
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"-i" | "--ip-address" => {
|
||||
|
|
@ -139,8 +131,9 @@ impl ClientConfig {
|
|||
println!(" -h, --help\t\t\tPrint help information");
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
invalid => return Err(format!("Invalid flag: {invalid}").into()),
|
||||
file_name => {
|
||||
config.filename = PathBuf::from(file_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
use std::error::Error;
|
||||
use std::env::args;
|
||||
use std::{env, net::SocketAddr, process};
|
||||
use tftpd::{Client, ClientConfig, Config, Mode, Server};
|
||||
use tftpd::{Client, ClientConfig, Mode};
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
client(args[0..].iter().map(|s| s.to_string())).unwrap_or_else(|err| {
|
||||
client(env::args()).unwrap_or_else(|err| {
|
||||
eprintln!("{err}");
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ use std::{env, net::SocketAddr, process};
|
|||
use tftpd::{Config, Server};
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
server(args[0..].iter().map(|s| s.to_string()));
|
||||
server(env::args());
|
||||
}
|
||||
|
||||
fn server<T: Iterator<Item = String>>(args: T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue