Fix argument parsing (whoops)

This whole command line thing is actually busted; probably should make
it a little bit more robust.
This commit is contained in:
John Doty 2024-07-31 14:56:50 -07:00
parent 3cb40bc2f4
commit 604f31d8e6

View file

@ -65,21 +65,21 @@ fn parse_args(args: Vec<String>) -> Args {
} else { } else {
Args::Error Args::Error
} }
} else if !rest.is_empty() { } else if rest.is_empty() {
if rest[0] == "browse" { Args::Error
if rest.len() == 2 { } else if rest[0] == "browse" {
Args::Browse(rest[1].to_string()) if rest.len() == 2 {
} else { Args::Browse(rest[1].to_string())
Args::Error } else if rest.len() == 1 {
} Args::Client(rest[0].to_string(), sudo.unwrap_or(false))
} else if rest[0] == "clip" { } else {
if rest.len() == 1 { Args::Error
Args::Clip(None) }
} else if rest.len() == 2 { } else if rest[0] == "clip" {
Args::Clip(Some(rest[1].to_string())) if rest.len() == 1 {
} else { Args::Clip(None)
Args::Error } else if rest.len() == 2 {
} Args::Clip(Some(rest[1].to_string()))
} else { } else {
Args::Error Args::Error
} }
@ -187,6 +187,11 @@ mod tests {
assert_arg_parse!(&["--server"], Args::Server); assert_arg_parse!(&["--server"], Args::Server);
} }
#[test]
fn clip() {
assert_arg_parse!(&["clip"], Args::Clip(None));
}
#[test] #[test]
fn browse() { fn browse() {
assert_arg_parse!(&["browse", "google.com"], Args::Browse(_)); assert_arg_parse!(&["browse", "google.com"], Args::Browse(_));