Commit graph

2412 commits

Author SHA1 Message Date
Alan K
df35813d17
fix: fixes compilation errors form cherry picked commits 2018-06-12 10:04:24 -04:00
Kevin K
24d5fb3202 test: Added regression tests for Issue 897 2018-06-12 10:01:42 -04:00
Kevin K
b4b4ab629d chore: forgot pre html tag 2018-06-12 09:55:44 -04:00
Kevin K
af3264d559 Merge pull request #1272 from bspeice/patch-1
examples: Method rename
2018-06-12 09:54:19 -04:00
Kevin K
4ebede6d9a Merge pull request #1271 from stevepentland/wasm-windows-fix
Include guards around os-specific string elements.
2018-06-12 09:53:22 -04:00
Kevin K
abd7be3362 Merge pull request #1247 from tormol/osstringext_cleanup
Remove unused or unnecessary methods from osstringext
2018-06-12 09:51:07 -04:00
Kevin K
b46297ef65
Merge pull request #1279 from zayenz/fix-compilation-error
fix(benches): Fix compilation error
2018-05-30 14:59:15 -04:00
Mikael Zayenz Lagerkvist
d83debd745 fix(benches): Fix compilation error 2018-05-29 18:24:40 +02:00
Kevin K
3b633e68b1
Merge pull request #1258 from little-dude/warnings
Fix compilation warnings
2018-05-22 09:43:31 -04:00
Kevin K
0d20694ce5
Merge pull request #1257 from little-dude/deprecate_from_usage
replace Arg::from_usage by Arg::from
2018-05-22 09:42:11 -04:00
Kevin K
d85f149949
Merge pull request #1256 from little-dude/string
convert Result<(), OsString> -> Result<(), String>
2018-05-22 09:31:16 -04:00
Corentin Henry
dcf00b76eb fix unused import warning 2018-04-21 13:06:11 -07:00
Corentin Henry
78cbb634a9 fix dead code warning 2018-04-21 12:17:48 -07:00
Corentin Henry
32fcd49fdf fix unused mut warnings 2018-04-21 12:14:49 -07:00
Corentin Henry
ff4ae462f5 fix unused variable warning 2018-04-21 12:14:05 -07:00
Corentin Henry
4f602b7e86 replace Arg::from_usage by Arg::from 2018-04-21 11:59:19 -07:00
Corentin Henry
e1f1a13e4d convert Result<(), OsString> -> Result<(), String>
fix https://github.com/kbknapp/clap-rs/issues/848
2018-04-21 11:24:59 -07:00
Kevin K
9981bac22a
Merge pull request #1243 from durka/flexible-validator
imp: make Arg::validator more flexible (v3)
2018-04-04 22:13:11 -04:00
Alex Burka
c5d79d854e test validator with custom return type 2018-04-04 20:45:22 -04:00
Alex Burka
c3033ca75f imp: make Arg::validator more flexible
Makes the validator functions more flexible by changing the return
type from Result<(), String> to Result<O, E> where O is anything
and E is anything convertible to a String.

This allows, for example, using the same function for validating
and parsing your argument.

Breaking change (albeit tiny) due to function signature change.
2018-04-04 20:34:40 -04:00
Kevin K
0822e2eecf
Merge pull request #1211 from willmurphyscode/805-experiment
Implementation of custom help sections
2018-04-03 23:35:42 -04:00
Kevin K
8973f229b0
feat(Help): adds the ability for custom help sections
Args can now be added to custom help sections. This breaks up the builder pattern a little by adding help section declarations inline, but it's the most intuitive method and doesn't require strange nesting that feels awkward.

```rust
app::new("foo")
    .arg(Arg::with_name("arg1")) // under normal headers
    .help_heading("SPECIAL")
    .arg(Arg::with_name("arg2")) // under SPECIAL: heading
```

Closes #805
2018-04-03 23:32:59 -04:00
Kevin K
4df65d8c90
Merge pull request #1241 from kbknapp/v3-dev
V3 dev
2018-04-03 23:25:09 -04:00
Christian Legnitto
36815fec59 imp(macros): Support shorthand syntax for ArgGroups
Fixes https://github.com/kbknapp/clap-rs/issues/1231.
2018-04-03 23:03:21 -04:00
Kevin K
41e29417b5 fix: fixes hiding args from short or long help in v3 context
Fixes the implementation of the hiding of arguments form the short or long help on v3
2018-04-03 23:01:45 -04:00
Kevin K
82e8a47f24 api(Arg): adds abilit to hide an arg from the short or long help message
Add logic to filter based on hidden long/short.

There is still an issue with the logic in parser.rs use_long_help. This
causes invalid evaluation of whether to show/hide based on long or short help
Complete check for use_long_help, add tests
2018-04-03 20:00:36 -04:00
Kevin K
c9159d392d
Merge pull request #1228 from kbknapp/v3-dev
V3 dev
2018-03-21 19:42:48 -04:00
Kevin K
8f1c0cfbbd
tests: fixes failing tests from new API additions 2018-03-21 19:41:58 -04:00
Kevin K
2264b255d3
api(App): adds App::unset_global_setting to be able to unset a globa setting 2018-03-21 19:32:41 -04:00
Kevin K
60c634be51
api(App): adds App::mut_arg to be able to mutate Args after they've been added to an App
Once can now mutate an Arg instance after it's already been added to an App struct.
This is helpful when you wish to add all the args in an non-verbose way, such as
via the usage strings, but wish for a handful to have settings which arne't posible
in the usage string definitions.
2018-03-21 19:26:22 -04:00
Kevin K
e5d44eac21
api(App): adds App::get_matches_mut for Lib Blitz style naming consitency 2018-03-21 15:12:47 -04:00
Kevin K
fba268ad54
refactor: changes the signature of App::args to be more generic 2018-03-21 15:05:30 -04:00
Kevin K
f23659619d
depr(App): adds plural settings and unset_settings to deprecations 2018-03-21 15:05:01 -04:00
Kevin K
564f63640c
Merge pull request #1227 from kbknapp/v3-dev
fix(Suggestions): disables suggestions when AllowExternalSubcommand i…
2018-03-21 00:05:21 -04:00
Aleksey Kladov
dfbae74e6d fix(Suggestions): disables suggestions when AllowExternalSubcommand is set 2018-03-21 00:01:23 -04:00
Kevin K
b73c7e8518
Merge pull request #1226 from kbknapp/v3-dev
V3 dev
2018-03-20 23:58:58 -04:00
Kevin K
a7b3a75cc4 api(Arg): adds Arg::raw as convenience method to indicate multiple, last, and allow_hyphen_values 2018-03-20 23:53:36 -04:00
Kevin K
d405cbf2e6 Add wasm support 2018-03-20 23:49:38 -04:00
Kevin K
875f6b884b
Merge pull request #1225 from kbknapp/v3-dev
V3 dev
2018-03-20 23:04:07 -04:00
Kevin K
f65e2e4bf5
fix(Indices): fixes Indices to work on v3 2018-03-20 23:03:09 -04:00
Kevin K
e2e15b79b7 feat(Arg Indices): adds the ability to query argument value indices
Adds the abiltiy to query the matches struct for the indices of values or flags. The index
is similar to that of an argv index, but not exactly a 1:1.

For flags (i.e. those arguments which don't have an associated value), indices refer
to occurrence of the switch, such as `-f`, or `--flag`. However, for options the indices
refer to the *values* `-o val` would therefore not represent two distinct indices, only the
index for `val` would be recorded. This is by design.

Besides the flag/option descrepancy, the primary difference between an argv index and clap
index, is that clap continues counting once all arguments have properly seperated, whereas
an argv index does not.

The examples should clear this up.

*NOTE:* If an argument is allowed multiple times, this method will only give the *first*
index.

The argv indices are listed in the comments below. See how they correspond to the clap
indices. Note that if it's not listed in a clap index, this is becuase it's not saved in
in an `ArgMatches` struct for querying.

```rust
let m = App::new("myapp")
    .arg(Arg::with_name("flag")
        .short("f"))
    .arg(Arg::with_name("option")
        .short("o")
        .takes_value(true))
    .get_matches_from(vec!["myapp", "-f", "-o", "val"]);
            // ARGV idices: ^0       ^1    ^2    ^3
            // clap idices:          ^1          ^3

assert_eq!(m.index_of("flag"), Some(1));
assert_eq!(m.index_of("option"), Some(3));
```

Now notice, if we use one of the other styles of options:

```rust
let m = App::new("myapp")
    .arg(Arg::with_name("flag")
        .short("f"))
    .arg(Arg::with_name("option")
        .short("o")
        .takes_value(true))
    .get_matches_from(vec!["myapp", "-f", "-o=val"]);
            // ARGV idices: ^0       ^1    ^2
            // clap idices:          ^1       ^3

assert_eq!(m.index_of("flag"), Some(1));
assert_eq!(m.index_of("option"), Some(3));
```

Things become much more complicated, or clear if we look at a more complex combination of
flags. Let's also throw in the final option style for good measure.

```rust
let m = App::new("myapp")
    .arg(Arg::with_name("flag")
        .short("f"))
    .arg(Arg::with_name("flag2")
        .short("F"))
    .arg(Arg::with_name("flag3")
        .short("z"))
    .arg(Arg::with_name("option")
        .short("o")
        .takes_value(true))
    .get_matches_from(vec!["myapp", "-fzF", "-oval"]);
            // ARGV idices: ^0      ^1       ^2
            // clap idices:         ^1,2,3    ^5
            //
            // clap sees the above as 'myapp -f -z -F -o val'
            //                         ^0    ^1 ^2 ^3 ^4 ^5
assert_eq!(m.index_of("flag"), Some(1));
assert_eq!(m.index_of("flag2"), Some(3));
assert_eq!(m.index_of("flag3"), Some(2));
assert_eq!(m.index_of("option"), Some(5));
```

One final combination of flags/options to see how they combine:

```rust
let m = App::new("myapp")
    .arg(Arg::with_name("flag")
        .short("f"))
    .arg(Arg::with_name("flag2")
        .short("F"))
    .arg(Arg::with_name("flag3")
        .short("z"))
    .arg(Arg::with_name("option")
        .short("o")
        .takes_value(true)
        .multiple(true))
    .get_matches_from(vec!["myapp", "-fzFoval"]);
            // ARGV idices: ^0       ^1
            // clap idices:          ^1,2,3^5
            //
            // clap sees the above as 'myapp -f -z -F -o val'
            //                         ^0    ^1 ^2 ^3 ^4 ^5
assert_eq!(m.index_of("flag"), Some(1));
assert_eq!(m.index_of("flag2"), Some(3));
assert_eq!(m.index_of("flag3"), Some(2));
assert_eq!(m.index_of("option"), Some(5));
```

The last part to mention is when values are sent in multiple groups with a [delimiter].

```rust
let m = App::new("myapp")
    .arg(Arg::with_name("option")
        .short("o")
        .takes_value(true)
        .multiple(true))
    .get_matches_from(vec!["myapp", "-o=val1,val2,val3"]);
            // ARGV idices: ^0       ^1
            // clap idices:             ^2   ^3   ^4
            //
            // clap sees the above as 'myapp -o val1 val2 val3'
            //                         ^0    ^1 ^2   ^3   ^4
assert_eq!(m.index_of("option"), Some(2));
```
2018-03-20 22:35:10 -04:00
Kevin K
ee5733fd0a fixup! docs(Arg Indices): adds the documentation for the arg index querying methods 2018-03-20 22:26:12 -04:00
Kevin K
89b74d5b31 fixup! tests: adds tests for querying indices 2018-03-20 22:25:58 -04:00
Kevin K
ad51b79300 docs(Values): improves the docs example of the Values iterator 2018-03-20 22:25:39 -04:00
Kevin K
ed96928eda feat(Indices): implements an Indices<Item=&usize> iterator 2018-03-20 22:25:32 -04:00
Kevin K
c3cd1c1a43 tests(Values): moves values tests into a tests mod 2018-03-20 22:25:23 -04:00
Kevin K
b59da93693 docs(Arg Indices): adds the documentation for the arg index querying methods 2018-03-20 22:25:17 -04:00
Kevin K
ed8bcc7632 tests: adds tests for querying indices 2018-03-20 22:25:10 -04:00
Kevin K
a2c2bb4991
Merge pull request #1223 from kbknapp/v3-dev
V3 dev
2018-03-20 21:01:29 -04:00
Kevin K
7b544e00d9 tests(AllowMissingPositional): adds tests for new 'skipping to last positional' with '--' 2018-03-20 20:57:14 -04:00