Skip to content

Commit

Permalink
fix no subcommand panic
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Sep 12, 2020
1 parent 37fce20 commit fe9728e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ impl SubCommand {
args: &'b [String],
) -> (String, Vec<String>, Option<String>) {
let is_dashed = self.name.starts_with('-'); // SubCommand of pacman is dashed
let name;
let mut options: Vec<String> = vec![];
let mut operands: Vec<String> = vec![];
for arg in args.iter() {
Expand All @@ -124,11 +123,22 @@ impl SubCommand {
operands.push(arg.to_string());
}
}
if is_dashed {
name = options.remove(0);
} else {
name = operands.remove(0);
}
let name = match is_dashed {
true => {
if options.len() == 0 {
String::new()
} else {
options.remove(0)
}
},
false => {
if operands.len() == 0 {
String::new()
} else {
operands.remove(0)
}
}
};
let pkg = if operands.is_empty() {
None
} else {
Expand Down

0 comments on commit fe9728e

Please sign in to comment.