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:
parent
3cb40bc2f4
commit
604f31d8e6
1 changed files with 20 additions and 15 deletions
35
src/main.rs
35
src/main.rs
|
|
@ -65,21 +65,21 @@ fn parse_args(args: Vec<String>) -> 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(_));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue