Commit graph

2867 commits

Author SHA1 Message Date
Guillaume Pinot
0a5edfd5ad v0.2.6 2018-03-31 15:50:56 +02:00
Guillaume P
91f4f41ee7 Improve the keyvalue example 2018-03-31 15:43:13 +02:00
Guillaume P
c9aff7c050 Fix link in CHANGELOG.md 2018-03-31 15:43:13 +02:00
Guillaume Pinot
94ea6452d2 Fail compilation when using default_value or required with bool
Fix #80
2018-03-30 23:35:30 +02:00
Guillaume Pinot
71e2c05ade Fix compilation with #[deny(warnings)] with the ! type
https://github.com/rust-lang/rust/pull/49039#issuecomment-376420816
2018-03-27 09:44:36 +02: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
Kevin K
219b96b672 imp(AllowMissingPositional): improves the ability of AllowMissingPositional to allow 'skipping' to the last positional arg with '--' 2018-03-20 20:54:26 -04:00
Thomas Vincent
ce62bcaa06 Fix the --nb-cars option in the example (#85) 2018-03-19 23:45:47 +01:00
Kevin K
59687be81f
Merge pull request #1218 from kbknapp/v3-dev
backporting 2.x fixes and features
2018-03-19 17:13:13 -04:00
Kevin K
91e275c609
Use short help as tooltip in PowerShell completion
Also fixed some small issues with subcommand detection.
2018-03-19 17:12:10 -04:00
Kevin K
bd5143d1f8
fish: Fix completion of >1 options 2018-03-19 17:12:06 -04:00
Matthias Krüger
1e3c715c47
Cargo.toml: use codegen-units = 1 in release and bench profiles. 2018-03-19 17:12:02 -04:00
Kevin K
92eab59dfc
docs: Fix some typos and markdown issues. 2018-03-19 17:11:59 -04:00
Katharina
919fd32dfb
Moving the line into the apropriate section 2018-03-19 17:11:57 -04:00
andy boot
a4d080370c fix typo 2018-03-19 16:48:01 -04:00
Kevin K
b74faf921d
Merge pull request #1217 from kbknapp/v3-dev
refactor(Arg): reverts some of the v3 deprecations to ease the upgrade process
2018-03-19 16:36:18 -04:00
Kevin K
82ffb821de
refactor(Arg): reverts some of the v3 deprecations to ease the upgrade process 2018-03-19 16:33:56 -04:00
William Murphy
b9e4c058fa
Merge pull request #1208 from willmurphyscode/args-first-in-help
Print ARGS immediately after usage in help
2018-03-15 18:15:35 -04:00
Guillaume P
c1ec5f9732 Improve the first example in the documentation
Fix #82
2018-03-15 11:14:59 +01:00
Guillaume P
73b6b672ca Add an example with at least 2 arguments 2018-03-15 10:37:28 +01:00
Guillaume P
495cc1f5e3 Add no_version example 2018-03-12 12:36:21 +01:00
Will Murphy
742aec292c Print ARGS after usage in help
For version 3, we want the args section to immediately follow
the usage section in the default help message.

One change that I am unhappy with is needing to make "write_arg"
in app/help.rs accept an extra param that makes it suppress the
extra line. This is to prevent an extra blank line from appearing
between args and options in the default help, and seems necessary,
but there might be a better way.
2018-03-11 20:33:13 -04:00
Guillaume P
b043260eb3 Add an example for KEY=value argument as asked in #79 2018-03-09 16:54:26 +01:00
Guillaume Pinot
d529fe6435 v0.2.5 2018-03-07 23:50:49 +01:00
Nick Fitzgerald
f9a7651619 Use proc_macro2::Span::call_site for all quotes (#77)
This avoids breakage when deriving `StructOpt` when `proc_macro2`'s nightly
feature is enabled. See https://github.com/alexcrichton/proc-macro2/issues/67
for details.
2018-03-07 23:47:41 +01:00
Kevin K
c3cfe8f7a4
Merge pull request #1202 from willmurphyscode/version-bump-term-size
bump version on term size to 1.0.0-beta1
2018-03-06 07:28:25 -05:00
Will Murphy
74421bb8b7 bump version on term size to 1.0.0-beta1 2018-03-06 06:36:59 -05:00