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>> {
|
pub fn new<T: Iterator<Item = String>>(mut args: T) -> Result<ClientConfig, Box<dyn Error>> {
|
||||||
let mut config = ClientConfig::default();
|
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() {
|
while let Some(arg) = args.next() {
|
||||||
match arg.as_str() {
|
match arg.as_str() {
|
||||||
"-i" | "--ip-address" => {
|
"-i" | "--ip-address" => {
|
||||||
|
|
@ -139,8 +131,9 @@ impl ClientConfig {
|
||||||
println!(" -h, --help\t\t\tPrint help information");
|
println!(" -h, --help\t\t\tPrint help information");
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
file_name => {
|
||||||
invalid => return Err(format!("Invalid flag: {invalid}").into()),
|
config.filename = PathBuf::from(file_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::env::args;
|
|
||||||
use std::{env, net::SocketAddr, process};
|
use std::{env, net::SocketAddr, process};
|
||||||
use tftpd::{Client, ClientConfig, Config, Mode, Server};
|
use tftpd::{Client, ClientConfig, Mode};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
client(env::args()).unwrap_or_else(|err| {
|
||||||
client(args[0..].iter().map(|s| s.to_string())).unwrap_or_else(|err| {
|
|
||||||
eprintln!("{err}");
|
eprintln!("{err}");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ use std::{env, net::SocketAddr, process};
|
||||||
use tftpd::{Config, Server};
|
use tftpd::{Config, Server};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
server(env::args());
|
||||||
server(args[0..].iter().map(|s| s.to_string()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server<T: Iterator<Item = String>>(args: T) {
|
fn server<T: Iterator<Item = String>>(args: T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue