mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
Merge pull request #11 from kbknapp/onlyposfollows
Closes #10 (Adds support for "--" where only positional arguments follow)
This commit is contained in:
commit
e6ca4cfc1b
1 changed files with 46 additions and 41 deletions
13
src/app.rs
13
src/app.rs
|
@ -703,13 +703,14 @@ impl App {
|
|||
fn get_matches_from(&mut self, matches: &mut ArgMatches, it: &mut IntoIter<String>) {
|
||||
self.create_help_and_version();
|
||||
|
||||
// let mut needs_val = false;
|
||||
let mut pos_only = false;
|
||||
let mut subcmd_name: Option<&'static str> = None;
|
||||
let mut needs_val_of: Option<&'static str> = None;
|
||||
let mut pos_counter = 1;
|
||||
while let Some(arg) = it.next() {
|
||||
let arg_slice = arg.as_slice();
|
||||
let mut skip = false;
|
||||
if ! pos_only {
|
||||
if let Some(nvo) = needs_val_of {
|
||||
if let Some(ref opt) = self.opts.get(nvo) {
|
||||
if self.blacklist.contains(opt.name) {
|
||||
|
@ -754,15 +755,19 @@ impl App {
|
|||
skip = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if skip {
|
||||
needs_val_of = None;
|
||||
continue;
|
||||
}
|
||||
if arg_slice.starts_with("--") {
|
||||
if arg_slice.starts_with("--") && ! pos_only {
|
||||
if arg_slice.len() == 2 {
|
||||
pos_only = true;
|
||||
continue;
|
||||
}
|
||||
// Single flag, or option long version
|
||||
needs_val_of = self.parse_long_arg(matches, &arg);
|
||||
|
||||
} else if arg_slice.starts_with("-") && arg_slice.len() != 1 {
|
||||
} else if arg_slice.starts_with("-") && arg_slice.len() != 1 && ! pos_only {
|
||||
needs_val_of = self.parse_short_arg(matches, &arg);
|
||||
} else {
|
||||
// Positional or Subcommand
|
||||
|
|
Loading…
Reference in a new issue