Compare commits

...

2 commits

Author SHA1 Message Date
604f31d8e6 Fix argument parsing (whoops)
This whole command line thing is actually busted; probably should make
it a little bit more robust.
2024-07-31 14:56:50 -07:00
3cb40bc2f4 Clippy 2024-07-31 14:45:20 -07:00

View file

@ -60,15 +60,18 @@ fn parse_args(args: Vec<String>) -> Args {
}
if server.unwrap_or(false) {
if rest.len() == 0 && sudo.is_none() {
if rest.is_empty() && sudo.is_none() {
Args::Server
} else {
Args::Error
}
} else if rest.len() >= 1 {
if rest[0] == "browse" {
} else if rest.is_empty() {
Args::Error
} else if rest[0] == "browse" {
if rest.len() == 2 {
Args::Browse(rest[1].to_string())
} else if rest.len() == 1 {
Args::Client(rest[0].to_string(), sudo.unwrap_or(false))
} else {
Args::Error
}
@ -80,9 +83,6 @@ fn parse_args(args: Vec<String>) -> Args {
} else {
Args::Error
}
} else {
Args::Error
}
} else if rest.len() == 1 {
Args::Client(rest[0].to_string(), sudo.unwrap_or(false))
} else {
@ -91,7 +91,7 @@ fn parse_args(args: Vec<String>) -> Args {
}
async fn browse_url(url: &str) {
if let Err(e) = fwd::browse_url(&url).await {
if let Err(e) = fwd::browse_url(url).await {
eprintln!("Unable to open {url}");
eprintln!("{}", e);
std::process::exit(1);
@ -141,8 +141,7 @@ mod tests {
// Goldarn it.
fn args(x: &[&str]) -> Vec<String> {
let mut vec: Vec<String> =
x.into_iter().map(|a| a.to_string()).collect();
let mut vec: Vec<String> = x.iter().map(|a| a.to_string()).collect();
vec.insert(0, "fwd".to_string());
vec
}
@ -188,6 +187,11 @@ mod tests {
assert_arg_parse!(&["--server"], Args::Server);
}
#[test]
fn clip() {
assert_arg_parse!(&["clip"], Args::Clip(None));
}
#[test]
fn browse() {
assert_arg_parse!(&["browse", "google.com"], Args::Browse(_));