Commit graph

74 commits

Author SHA1 Message Date
Kevin K
4cc85990fd
refactor: removed strings as an internal ID for arguments, groups, and
subcommands

This commit changes the internal ID to a u64 which will allow for
greater optimizations down the road. In addition, it lays the ground
work for allowing users to use things like enum variants as argument
keys instead of strings.

The only downside is each key needs to be hashed (the implementation
used is an FNV hasher for performance). However, the performance gains
in faster iteration, comparison, etc. should easily outweigh the single
hash of each argument.

Another benefit of if this commit is the removal of several lifetime
parameters, as it stands Arg and App now only have a single lifetime
parameter, and ArgMatches and ArgGroup have no lifetime parameter.
2019-04-05 20:21:22 -04:00
Kevin K
20c72525d2 style: cargo fmt run 2018-11-14 12:05:06 -05:00
Kevin K
0de9e07412
Merge branch 'v3-master' into map 2018-11-13 22:07:16 -05:00
Kevin K
471376fdc7 imp: no longer automatically forces user to handle help just by overriding help arg 2018-10-20 22:27:31 -04:00
Kevin K
20126e1f62 refactor: fixes test failures from removing deprecations 2018-10-20 21:54:29 -04:00
Kevin K
03333800fe refactor: remove code going to other crates and deprecations 2018-10-19 23:31:06 -04:00
Kevin K
400fafade2
tests: fixes help tests 2018-08-27 20:25:37 -04:00
Kevin K
49defad11b
fix: fixes help output tests 2018-08-01 22:09:09 -04:00
Kevin K
94872e00a5
refactor(Arg): changes Arg::short to accept a char instead of &str
Closes #1303
2018-07-23 15:10:12 -04:00
Kevin K
24d5fb3202 test: Added regression tests for Issue 897 2018-06-12 10:01:42 -04:00
Corentin Henry
4f602b7e86 replace Arg::from_usage by Arg::from 2018-04-21 11:59:19 -07: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
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
Kevin K
08dfdc877b
style: changes values->possible values in help messages as well as errors 2018-02-12 14:52:29 -05:00
Kevin K
97fd3f1328
tests: partially updates tests to new arg.setting calls 2018-02-03 15:06:58 -05:00
Kevin K
78090e5529
tests: removes some instances of println in the tests 2018-01-25 22:36:20 -05:00
Kevin K
1ab10275e4
style: rustfmt run 2018-01-25 12:21:17 -05:00
Kevin K
ebc35bdc91
tests: adds tests for both showing and hiding the values inside ENV vars 2017-12-02 15:09:22 -05:00
Kevin K
89c0ed0328
tests: adds tests to guard against --help and -h being overridable 2017-11-22 04:11:28 -05:00
Kevin K
3e645ae9fc
tests: adds tests for required delimiters appearing in the help and usage strings 2017-10-12 15:11:51 -07:00
Kevin K
8567f0a46e
tests: adds tests to guard against subcommand section of help message showing unnecessarily 2017-09-14 10:38:01 -07:00
Kevin K
0136e991c4
tests: adds tests for App::long_about 2017-09-13 11:41:49 -07:00
Fraser Hutchison
b3eadb0de5 fix: avoid panic generating default help msg if term width set to 0 due to bug in textwrap 0.7.0
upgrade textwrap to 0.8.0 and add regression test
2017-09-07 00:19:08 +01:00
Corentin Henry
e8518cf07d tests(Suggestions): update tests for subcommand suggestions 2017-06-12 08:03:39 -07:00
Martin Geisler
b93870c10a feat: use textwrap crate for wrapping help texts
The textwrap crate uses a simpler linear-time algorithm for wrapping
the text. The current algorithm in wrap_help uses several O(n) calls
to String::insert and String::remove, which makes it potentially
quadratic in complexity.

Comparing the 05_ripgrep benchmark at commits textwrap~2 and textwrap
gives this result on my machine:

 name              before ns/iter  after ns/iter  diff ns/iter   diff %
 build_app_long    22,101          21,099               -1,002   -4.53%
 build_app_short   22,138          21,205                 -933   -4.21%
 build_help_long   514,265         284,467            -229,798  -44.68%
 build_help_short  85,720          85,693                  -27   -0.03%
 parse_clean       23,471          22,859                 -612   -2.61%
 parse_complex     29,535          28,919                 -616   -2.09%
 parse_lots        422,815         414,577              -8,238   -1.95%

As part of this commit, the wrapping_newline_chars test was updated.
The old algorithm had a subtle bug where it would break lines too
early. That is, it wrapped the text like

    ARGS:
        <mode>    x, max, maximum   20 characters, contains
                  symbols.
                  l, long           Copy-friendly,
                  14 characters, contains symbols.
                  m, med, medium    Copy-friendly, 8
                  characters, contains symbols.";

when it should really have wrapped it like

    ARGS:
        <mode>    x, max, maximum   20 characters, contains
                  symbols.
                  l, long           Copy-friendly, 14
                  characters, contains symbols.
                  m, med, medium    Copy-friendly, 8
                  characters, contains symbols.";

Notice how the word "14" was incorrectly moved to the next line. There
is clearly room for the word on the line with the "l, long" option
since there is room for "contains" just above it.

I'm not sure why this is, but the algorithm in textwrap handles this
case correctly.
2017-05-29 17:02:57 -04:00
Martin Geisler
13653042c2 tests: add wrap_help test with significant whitepace
This adds a test for the issue #617 about keeping whitespace intact in
manually aligned text.
2017-05-29 17:02:57 -04:00
golem131
60cc838a42 Fix tests 2017-05-11 20:45:15 -04:00
Kevin K
54c16836de fix: fixes a bug where positional argument help text is misaligned 2017-05-10 20:29:54 -04:00
Kevin K
3223f21a90 tests: adds tests to last(true) args are printed in the usage even when required 2017-05-07 10:46:03 -04:00
Kevin K
3ed0f70c6e tests: adds tests to ensure positional values value name are used in usage strings instead of names when defined 2017-05-07 10:46:03 -04:00
Kevin K
6aa4ba8114 fix: fixes a missing newline character in the autogenerated help and version messages in some instances 2017-04-05 10:59:55 -04:00
Kevin K
92cc30577d tests: adds tests to verify help and version can be properly overridden 2017-04-04 19:56:34 -04:00
Kevin K
0e4fd96d74 fix(Custom Usage Strings): fixes the usage string regression when using help templates 2017-03-30 13:30:23 -04:00
Kevin K
1a97f4fb95 tests: adds regression tests for custom usage strings 2017-03-24 11:27:23 -04:00
CrazyMerlyn
6b491c1161
tests(Help): adds tests for per argument hiding of default value 2017-03-22 20:27:20 -04:00
Kevin K
3a10353f4b
tests: adds tests for .last(true) args 2017-03-11 12:14:54 -05:00
Kevin K
642db9b042
tests: adds tests for new dual usage strings with certain subcommand settings 2017-03-10 08:24:29 -05:00
Caleb Jones
389c413b70 Allow customizing the --version and --help messages 2017-03-10 01:01:56 -05:00
Kevin K
0efa411963
perf: refactor to remove unneeded vectors and allocations and checks for significant performance increases
Building an `App` struct with a fair number of args/flags/switches, etc. (used ripgrep as test case)
went from taking ~21,000 ns to ~13,000ns.
2017-02-28 08:30:13 -05:00
Martin Geisler
564c5f0f17 fix: allow final word to be wrapped in wrap_help
Before, inserting a newline did not move the prev_space index forward.
This meant that the next word was measured incorrectly since the
length was measured back to the word before the newly inserted
linebreak.

Fixes #828.
2017-01-30 18:33:48 +01:00
Martin Geisler
563a539a8e tests: show how final word is not always wrapped
This is #828.
2017-01-30 18:33:48 +01:00
Martin Geisler
aff4ba18da fix: include final character in line lenght
Before, wrapping the help text at, say, 80 characters really meant
that every line could be at most 79 characters wide.

Lines can now be up to and including avail_chars columns wide.

If needed, a desired margin or padding can be subtracted from the
avail_chars argument at a later point.
2017-01-30 18:33:48 +01:00
Kevin K
2fc5acaff7
fixup! tests: adds tests for propogating values down 2017-01-02 23:10:46 -05:00
Kevin K
f967235a90
tests: massively rehauls tests for better debugging and vastly improved error messages/deduplication 2017-01-02 23:05:50 -05:00
Kevin K
fc3800b830
tests: adds tests for wrapping meta help items 2017-01-02 16:44:40 -05:00
Kevin K
29e362cc19
tests: adds tests against issue 760 help message alignment 2016-12-01 18:47:20 -05:00
Kevin K
b94f897daf
tests(Help Message): adds tests to guard aginst multiple values throwing off alignment 2016-10-24 05:56:21 -04:00
Kevin K
637d25dde3
tests: adds tests to guard against issue-688 2016-10-20 19:39:21 -04:00
Salim Afiune
33b5f6ef2c feat(arg_aliases): Ability to alias arguments
There are some cases where you need to have an argument to have an
alias, an example could be when you depricate one option in favor of
another one.

Now you are going to be able to alias arguments as follows:
```
Arg::with_name("opt")
    .long("opt")
    .short("o")
    .takes_value(true)
    .alias("invisible")
    .visible_alias("visible")
```

Closes #669
2016-10-04 12:26:51 -04:00
Kevin K
1ea9bef20d
test(Help Wrapping): adds tests for the old newline characters 2016-09-12 23:20:40 -04:00