The method `starts_with` as implemented for the `OsStrExt2` trait on
`OsStr` assumed that the needle given is shorter than the haystack. When
this is not the case, the method panics due to an attempted
out-of-bounds access on the byte representation of `self`. Problematic
if, say, an end-user gives us `"-"` and the library tries to see if that
starts with `"--"`.
Fortunately, slices already implement a `starts_with` method, and we can
delegate to it.
This *does* create a semantics change: if both `self` and the needle
have length 0, this implementation will return `true`, but the old
implementation would return `false`. Based on the test suite still
passing, acknowledging the vacuous truth doesn't seem to cause any
problems.
Fixes#410
Bug fixes, new setting, code clean up, and added support u64::max values per arg
This turned into a little more than just a quick bug fix 😜
Thanks to #409 I've piggy backed on that and added support for > 256 values as well.
There's also just a bunch of code deduping and super small macro cleanups.
After this merges I'll put out 2.0.3
Allow for more than 256 occurrences of an argument.
Hi,
I often use tools with `xargs` and the like, and it's entirely possible to end up with inhumanly long sets of parameters being passed to a command.
Without this fix, the library will panic with an arithmetic overflow in `ArgMatcher#inc_occurrence_of` when the 256th instance of the parameter is accounted for.
Thanks,
chore: bump dependencies bitflags and yaml-rust to latest version
Bump `bitflags` from 0.3.3 to 0.4.0 and `yaml-rust` from 0.2.2 to 0.3.0.
All tests pass in current stable, beta and nightly (`1.8.0-nightly (38e23e8f7 2016-01-27)`).
External subcommands are now supported via the following:
```rust
extern crate clap;
use clap::{App, AppSettings};
fn main() {
// Assume there is a third party subcommand named myprog-subcmd
let m = App::new("myprog")
.setting(AppSettings::AllowExternalSubcommands)
.get_matches_from(vec![
"myprog", "subcmd", "--option", "value", "-fff", "--flag"
]);
// All trailing arguments will be stored under the subcommands sub-matches under a
// value of their runtime name (in this case "subcmd")
match m.subcommand() {
(external, Some(ext_m)) => {
let ext_args: Vec<&str> = ext_m.values_of(external).unwrap().collect();
assert_eq!(ext_args ,["--option", "value", "-fff", "--flag"]);
},
_ => unreachable!()
}
}
```
Closes#372