From 604f31d8e68f9c6ee3f9a286d0cf7e9074cd4f22 Mon Sep 17 00:00:00 2001 From: John Doty Date: Wed, 31 Jul 2024 14:56:50 -0700 Subject: [PATCH] Fix argument parsing (whoops) This whole command line thing is actually busted; probably should make it a little bit more robust. --- src/main.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index b433022..70008f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,21 +65,21 @@ fn parse_args(args: Vec) -> Args { } else { Args::Error } - } else if !rest.is_empty() { - if rest[0] == "browse" { - if rest.len() == 2 { - Args::Browse(rest[1].to_string()) - } else { - Args::Error - } - } else if rest[0] == "clip" { - if rest.len() == 1 { - Args::Clip(None) - } else if rest.len() == 2 { - Args::Clip(Some(rest[1].to_string())) - } else { - Args::Error - } + } 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 + } + } else if rest[0] == "clip" { + if rest.len() == 1 { + Args::Clip(None) + } else if rest.len() == 2 { + Args::Clip(Some(rest[1].to_string())) } else { Args::Error } @@ -187,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(_));