2021-11-30 15:31:19 +00:00
|
|
|
use crate::utils;
|
2015-09-09 02:39:31 +00:00
|
|
|
|
2022-02-12 03:48:29 +00:00
|
|
|
use clap::{arg, error::ErrorKind, Arg, ArgGroup, Command, PossibleValue};
|
2016-05-09 03:20:50 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static REQUIRE_DELIM_HELP: &str = "test 1.3
|
2017-10-12 22:11:51 +00:00
|
|
|
Kevin K.
|
|
|
|
tests stuff
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test --fake <some>:<val>
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-09-24 15:58:39 +00:00
|
|
|
-f, --fake <some>:<val> some help
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2017-10-12 22:11:51 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static HELP: &str = "clap-test v1.4.8
|
2016-05-09 03:20:50 +00:00
|
|
|
Kevin K. <kbknapp@gmail.com>
|
|
|
|
tests clap library
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
clap-test [OPTIONS] [ARGS] [SUBCOMMAND]
|
2016-05-09 03:20:50 +00:00
|
|
|
|
2018-03-07 11:23:20 +00:00
|
|
|
ARGS:
|
|
|
|
<positional> tests positionals
|
|
|
|
<positional2> tests positionals with exclusions
|
|
|
|
<positional3>... tests specific values [possible values: vi, emacs]
|
|
|
|
|
2016-05-09 03:20:50 +00:00
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-f, --flag tests flags
|
|
|
|
-F tests flags with exclusions
|
|
|
|
-h, --help Print help information
|
2016-05-09 03:20:50 +00:00
|
|
|
--long-option-2 <option2> tests long options with exclusions
|
|
|
|
--maxvals3 <maxvals>... Tests 3 max vals
|
|
|
|
--minvals2 <minvals>... Tests 2 min vals
|
2020-07-18 17:47:04 +00:00
|
|
|
--multvals <one> <two> Tests multiple values, not mult occs
|
|
|
|
--multvalsmo <one> <two> Tests multiple values, and mult occs
|
2016-05-09 03:20:50 +00:00
|
|
|
-o, --option <opt>... tests options
|
2021-10-26 22:22:35 +00:00
|
|
|
-O, --option3 <option3> specific vals [possible values: fast, slow]
|
2022-01-26 15:23:35 +00:00
|
|
|
--optvaleq[=<optval>] Tests optional value, require = sign
|
|
|
|
--optvalnoeq [<optval>] Tests optional value
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2016-05-09 03:20:50 +00:00
|
|
|
|
|
|
|
SUBCOMMANDS:
|
2021-07-30 03:23:25 +00:00
|
|
|
help Print this message or the help of the given subcommand(s)
|
2021-09-24 15:58:39 +00:00
|
|
|
subcmd tests subcommands
|
|
|
|
";
|
2016-05-09 03:20:50 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static SC_NEGATES_REQS: &str = "prog 1.0
|
2017-03-09 13:52:37 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
prog --opt <FILE> [PATH]
|
|
|
|
prog [PATH] <SUBCOMMAND>
|
|
|
|
|
2018-03-07 11:23:20 +00:00
|
|
|
ARGS:
|
|
|
|
<PATH> help
|
|
|
|
|
2017-03-09 13:52:37 +00:00
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
2017-03-09 13:52:37 +00:00
|
|
|
-o, --opt <FILE> tests options
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2017-03-09 13:52:37 +00:00
|
|
|
|
|
|
|
SUBCOMMANDS:
|
2021-07-30 03:23:25 +00:00
|
|
|
help Print this message or the help of the given subcommand(s)
|
2021-09-24 15:58:39 +00:00
|
|
|
test
|
|
|
|
";
|
2017-03-09 13:52:37 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static ARGS_NEGATE_SC: &str = "prog 1.0
|
2017-03-09 13:52:37 +00:00
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
prog [OPTIONS] [PATH]
|
2017-03-09 13:52:37 +00:00
|
|
|
prog <SUBCOMMAND>
|
|
|
|
|
2018-03-07 11:23:20 +00:00
|
|
|
ARGS:
|
|
|
|
<PATH> help
|
|
|
|
|
2017-03-09 13:52:37 +00:00
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-f, --flag testing flags
|
|
|
|
-h, --help Print help information
|
2017-03-09 13:52:37 +00:00
|
|
|
-o, --opt <FILE> tests options
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2017-03-09 13:52:37 +00:00
|
|
|
|
|
|
|
SUBCOMMANDS:
|
2021-07-30 03:23:25 +00:00
|
|
|
help Print this message or the help of the given subcommand(s)
|
2021-09-24 15:58:39 +00:00
|
|
|
test
|
|
|
|
";
|
2017-03-09 13:52:37 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static AFTER_HELP: &str = "some text that comes before the help
|
2016-05-30 10:01:00 +00:00
|
|
|
|
|
|
|
clap-test v1.4.8
|
|
|
|
tests clap library
|
|
|
|
|
|
|
|
USAGE:
|
2016-06-24 04:17:04 +00:00
|
|
|
clap-test
|
2016-05-30 10:01:00 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2016-05-30 10:01:00 +00:00
|
|
|
|
2021-09-24 15:58:39 +00:00
|
|
|
some text that comes after the help
|
|
|
|
";
|
2016-05-30 10:01:00 +00:00
|
|
|
|
2020-07-11 15:06:57 +00:00
|
|
|
static AFTER_LONG_HELP: &str = "some longer text that comes before the help
|
|
|
|
|
|
|
|
clap-test v1.4.8
|
|
|
|
tests clap library
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
clap-test
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-08-20 12:45:38 +00:00
|
|
|
-h, --help
|
2021-07-30 03:23:25 +00:00
|
|
|
Print help information
|
2020-07-11 15:06:57 +00:00
|
|
|
|
2020-08-20 12:45:38 +00:00
|
|
|
-V, --version
|
2021-07-30 03:23:25 +00:00
|
|
|
Print version information
|
2020-07-11 15:06:57 +00:00
|
|
|
|
2021-09-24 15:58:39 +00:00
|
|
|
some longer text that comes after the help
|
|
|
|
";
|
2020-07-11 15:06:57 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static HIDDEN_ARGS: &str = "prog 1.0
|
2017-03-09 13:52:37 +00:00
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
prog [OPTIONS]
|
2017-03-09 13:52:37 +00:00
|
|
|
|
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-f, --flag testing flags
|
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-o, --opt <FILE> tests options
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2017-03-09 13:52:37 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static SC_HELP: &str = "clap-test-subcmd 0.1
|
2016-05-09 03:20:50 +00:00
|
|
|
Kevin K. <kbknapp@gmail.com>
|
|
|
|
tests subcommands
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
clap-test subcmd [OPTIONS] [--] [scpositional]
|
2016-05-09 03:20:50 +00:00
|
|
|
|
2018-03-07 11:23:20 +00:00
|
|
|
ARGS:
|
|
|
|
<scpositional> tests positionals
|
|
|
|
|
2016-05-09 03:20:50 +00:00
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-f, --flag tests flags
|
|
|
|
-h, --help Print help information
|
2017-06-07 23:53:03 +00:00
|
|
|
-o, --option <scoption>... tests options
|
2021-09-24 15:58:39 +00:00
|
|
|
-s, --subcmdarg <subcmdarg> tests other args
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2016-01-13 17:03:27 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static ISSUE_1046_HIDDEN_SCS: &str = "prog 1.0
|
2017-09-14 17:37:13 +00:00
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
prog [OPTIONS] [PATH]
|
2017-09-14 17:37:13 +00:00
|
|
|
|
2018-03-07 11:23:20 +00:00
|
|
|
ARGS:
|
|
|
|
<PATH> some
|
|
|
|
|
2017-09-14 17:37:13 +00:00
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-f, --flag testing flags
|
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-o, --opt <FILE> tests options
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2017-09-14 17:37:13 +00:00
|
|
|
|
2021-06-16 05:28:25 +00:00
|
|
|
// Using number_of_values(1) with multiple_values(true) misaligns help message
|
2019-10-02 13:27:19 +00:00
|
|
|
static ISSUE_760: &str = "ctest 0.1
|
2016-12-01 23:47:20 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
2021-08-17 09:17:18 +00:00
|
|
|
-o, --option <option> tests options
|
2021-09-24 15:58:39 +00:00
|
|
|
-O, --opt <opt> tests options
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2016-12-01 23:47:20 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static RIPGREP_USAGE: &str = "ripgrep 0.5
|
2017-03-24 03:51:43 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
rg [OPTIONS] <pattern> [<path> ...]
|
|
|
|
rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
|
|
|
|
rg [OPTIONS] --files [<path> ...]
|
|
|
|
rg [OPTIONS] --type-list
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2017-03-24 03:51:43 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static MULTI_SC_HELP: &str = "ctest-subcmd-multi 0.1
|
2016-08-20 21:14:18 +00:00
|
|
|
Kevin K. <kbknapp@gmail.com>
|
|
|
|
tests subcommands
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
ctest subcmd multi [OPTIONS]
|
2016-08-20 21:14:18 +00:00
|
|
|
|
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-f, --flag tests flags
|
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-o, --option <scoption>... tests options
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2016-08-20 21:14:18 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static ISSUE_626_CUTOFF: &str = "ctest 0.1
|
2016-08-25 01:50:20 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2016-09-06 00:46:18 +00:00
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café is an
|
|
|
|
establishment which primarily serves hot
|
2016-09-07 12:42:42 +00:00
|
|
|
coffee, related coffee beverages (e.g., café
|
|
|
|
latte, cappuccino, espresso), tea, and other
|
|
|
|
hot beverages. Some coffeehouses also serve
|
|
|
|
cold beverages such as iced coffee and iced
|
2017-01-08 11:51:20 +00:00
|
|
|
tea. Many cafés also serve some type of food,
|
2021-09-24 15:58:39 +00:00
|
|
|
such as light snacks, muffins, or pastries.
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2016-08-25 01:50:20 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static ISSUE_626_PANIC: &str = "ctest 0.1
|
2016-08-25 01:50:20 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2016-08-28 03:42:31 +00:00
|
|
|
-c, --cafe <FILE>
|
2016-09-06 00:46:18 +00:00
|
|
|
La culture du café est très développée
|
|
|
|
dans de nombreux pays à climat chaud
|
2016-09-07 12:42:42 +00:00
|
|
|
d\'Amérique, d\'Afrique et d\'Asie, dans
|
|
|
|
des plantations qui sont cultivées pour
|
|
|
|
les marchés d\'exportation. Le café est
|
|
|
|
souvent une contribution majeure aux
|
2021-09-24 15:58:39 +00:00
|
|
|
exportations des régions productrices.
|
2021-10-11 22:01:33 +00:00
|
|
|
|
|
|
|
-h, --help
|
|
|
|
Print help information
|
|
|
|
|
|
|
|
-V, --version
|
|
|
|
Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2016-08-25 01:50:20 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static HIDE_POS_VALS: &str = "ctest 0.1
|
2016-09-11 03:08:40 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café.
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-p, --pos <VAL> Some vals [possible values: fast, slow]
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2016-09-11 03:08:40 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static FINAL_WORD_WRAPPING: &str = "ctest 0.1
|
2017-01-29 19:54:47 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2017-01-29 19:54:47 +00:00
|
|
|
-h, --help
|
2021-07-30 03:23:25 +00:00
|
|
|
Print help
|
2017-01-29 19:54:47 +00:00
|
|
|
information
|
2020-08-11 22:20:34 +00:00
|
|
|
|
2017-01-29 19:54:47 +00:00
|
|
|
-V, --version
|
2021-07-30 03:23:25 +00:00
|
|
|
Print
|
2017-01-29 10:46:23 +00:00
|
|
|
version
|
2021-09-24 15:58:39 +00:00
|
|
|
information
|
|
|
|
";
|
2017-01-29 19:54:47 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static OLD_NEWLINE_CHARS: &str = "ctest 0.1
|
2016-09-13 03:20:40 +00:00
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
ctest [OPTIONS]
|
2016-09-13 03:20:40 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2016-09-13 03:20:40 +00:00
|
|
|
-m Some help with some wrapping
|
|
|
|
(Defaults to something)
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2016-09-13 03:20:40 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static WRAPPING_NEWLINE_CHARS: &str = "ctest 0.1
|
2017-01-29 20:38:30 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [mode]
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<mode> x, max, maximum 20 characters, contains
|
|
|
|
symbols.
|
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-01-28 11:42:09 +00:00
|
|
|
l, long Copy-friendly, 14
|
|
|
|
characters, contains symbols.
|
2017-01-29 20:38:30 +00:00
|
|
|
m, med, medium Copy-friendly, 8
|
2018-03-07 11:23:20 +00:00
|
|
|
characters, contains symbols.
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2016-10-20 23:37:39 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static ISSUE_688: &str = "ctest 0.1
|
2016-10-20 23:37:39 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
--filter <filter> Sets the filter, or sampling method, to use for interpolation when resizing the particle
|
2018-02-12 19:52:29 +00:00
|
|
|
images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic,
|
2021-09-24 15:58:39 +00:00
|
|
|
Gaussian, Lanczos3]
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2016-10-20 23:37:39 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static ISSUE_702: &str = "myapp 1.0
|
2016-10-24 09:56:21 +00:00
|
|
|
foo
|
|
|
|
bar
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
myapp [OPTIONS] [--] [ARGS]
|
|
|
|
|
2018-03-07 11:23:20 +00:00
|
|
|
ARGS:
|
|
|
|
<arg1> some option
|
|
|
|
<arg2>... some option
|
|
|
|
|
2016-10-24 09:56:21 +00:00
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
2016-10-24 09:56:21 +00:00
|
|
|
-l, --label <label>... a label
|
|
|
|
-o, --other <other> some other option
|
2021-09-24 15:58:39 +00:00
|
|
|
-s, --some <some> some option
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2016-10-24 09:56:21 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
static ISSUE_777: &str = "A cmd with a crazy very long long
|
2017-01-02 21:44:40 +00:00
|
|
|
long name hahaha 1.0
|
|
|
|
Some Very Long Name and crazy long
|
|
|
|
email <email@server.com>
|
|
|
|
Show how the about text is not
|
|
|
|
wrapped
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2017-01-02 21:44:40 +00:00
|
|
|
-h, --help
|
2021-07-30 03:23:25 +00:00
|
|
|
Print help information
|
2017-04-05 14:41:10 +00:00
|
|
|
|
2017-01-02 21:44:40 +00:00
|
|
|
-V, --version
|
2021-07-30 03:23:25 +00:00
|
|
|
Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
information
|
|
|
|
";
|
2017-01-02 21:44:40 +00:00
|
|
|
|
2020-08-11 21:46:09 +00:00
|
|
|
static ISSUE_1642: &str = "prog
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
prog [OPTIONS]
|
2020-08-11 21:46:09 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-08-20 12:45:38 +00:00
|
|
|
--config
|
2020-08-11 21:46:09 +00:00
|
|
|
The config file used by the myprog must be in JSON format
|
|
|
|
with only valid keys and may not contain other nonsense
|
|
|
|
that cannot be read by this program. Obviously I'm going on
|
|
|
|
and on, so I'll stop now.
|
2020-08-11 22:20:34 +00:00
|
|
|
|
2020-08-20 12:45:38 +00:00
|
|
|
-h, --help
|
2021-07-30 03:23:25 +00:00
|
|
|
Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2020-08-11 21:46:09 +00:00
|
|
|
|
2020-04-08 20:26:05 +00:00
|
|
|
static HELP_CONFLICT: &str = "conflict
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
conflict [OPTIONS]
|
2020-04-08 20:26:05 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-10-08 17:05:40 +00:00
|
|
|
-h
|
|
|
|
--help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2020-04-08 20:26:05 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static LAST_ARG: &str = "last 0.1
|
2017-03-11 05:17:57 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
last <TARGET> [CORPUS] [-- <ARGS>...]
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<TARGET> some
|
|
|
|
<CORPUS> some
|
2018-03-07 11:23:20 +00:00
|
|
|
<ARGS>... some
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2017-03-11 05:17:57 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static LAST_ARG_SC: &str = "last 0.1
|
2017-03-11 05:17:57 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
last <TARGET> [CORPUS] [-- <ARGS>...]
|
|
|
|
last <SUBCOMMAND>
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<TARGET> some
|
|
|
|
<CORPUS> some
|
|
|
|
<ARGS>... some
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2018-03-07 11:23:20 +00:00
|
|
|
|
2017-03-11 05:17:57 +00:00
|
|
|
SUBCOMMANDS:
|
2021-07-30 03:23:25 +00:00
|
|
|
help Print this message or the help of the given subcommand(s)
|
2021-09-24 15:58:39 +00:00
|
|
|
test some
|
|
|
|
";
|
2017-03-11 05:17:57 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static LAST_ARG_REQ: &str = "last 0.1
|
2017-03-11 05:17:57 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
last <TARGET> [CORPUS] -- <ARGS>...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<TARGET> some
|
|
|
|
<CORPUS> some
|
2018-03-07 11:23:20 +00:00
|
|
|
<ARGS>... some
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2017-03-11 05:17:57 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static LAST_ARG_REQ_SC: &str = "last 0.1
|
2017-03-11 05:17:57 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
last <TARGET> [CORPUS] -- <ARGS>...
|
|
|
|
last <SUBCOMMAND>
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<TARGET> some
|
|
|
|
<CORPUS> some
|
|
|
|
<ARGS>... some
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2018-03-07 11:23:20 +00:00
|
|
|
|
2017-03-11 05:17:57 +00:00
|
|
|
SUBCOMMANDS:
|
2021-07-30 03:23:25 +00:00
|
|
|
help Print this message or the help of the given subcommand(s)
|
2021-09-24 15:58:39 +00:00
|
|
|
test some
|
|
|
|
";
|
2017-03-11 05:17:57 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static HIDE_DEFAULT_VAL: &str = "default 0.1
|
2017-03-22 10:14:02 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
default [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-09-24 15:58:39 +00:00
|
|
|
--arg <argument> Pass an argument to the program. [default: default-argument]
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2017-03-22 10:14:02 +00:00
|
|
|
|
2020-09-23 08:45:14 +00:00
|
|
|
static ESCAPED_DEFAULT_VAL: &str = "default 0.1
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
default [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
--arg <argument> Pass an argument to the program. [default: \"\\n\"] [possible values: normal, \" \", \"\\n\", \"\\t\",
|
2021-09-24 15:58:39 +00:00
|
|
|
other]
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2020-09-23 08:45:14 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static LAST_ARG_USAGE: &str = "flamegraph 0.1
|
2017-05-06 23:52:12 +00:00
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
flamegraph [OPTIONS] [BINFILE] [-- <ARGS>...]
|
2017-05-06 23:52:12 +00:00
|
|
|
|
2018-03-07 11:23:20 +00:00
|
|
|
ARGS:
|
|
|
|
<BINFILE> The path of the binary to be profiled. for a binary.
|
|
|
|
<ARGS>... Any arguments you wish to pass to the being profiled.
|
|
|
|
|
2017-05-06 23:52:12 +00:00
|
|
|
OPTIONS:
|
2017-05-11 15:17:28 +00:00
|
|
|
-f, --frequency <HERTZ> The sampling frequency.
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-t, --timeout <SECONDS> Timeout in seconds.
|
2021-10-11 22:01:33 +00:00
|
|
|
-v, --verbose Prints out more stuff.
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2017-05-06 23:52:12 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static LAST_ARG_REQ_MULT: &str = "example 1.0
|
2017-05-07 00:18:11 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
example <FIRST>... [--] <SECOND>...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<FIRST>... First
|
2018-03-07 11:23:20 +00:00
|
|
|
<SECOND>... Second
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2017-05-07 00:18:11 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static DEFAULT_HELP: &str = "ctest 1.0
|
2017-09-06 23:19:08 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2017-09-06 23:19:08 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static LONG_ABOUT: &str = "myapp 1.0
|
2017-09-13 18:41:49 +00:00
|
|
|
foo
|
|
|
|
something really really long, with
|
|
|
|
multiple lines of text
|
|
|
|
that should be displayed
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
myapp [arg1]
|
|
|
|
|
2018-03-07 11:23:20 +00:00
|
|
|
ARGS:
|
2020-08-20 12:45:38 +00:00
|
|
|
<arg1>
|
2018-03-07 11:23:20 +00:00
|
|
|
some option
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-08-20 12:45:38 +00:00
|
|
|
-h, --help
|
2021-07-30 03:23:25 +00:00
|
|
|
Print help information
|
2017-09-13 18:41:49 +00:00
|
|
|
|
2020-08-20 12:45:38 +00:00
|
|
|
-V, --version
|
2021-09-24 15:58:39 +00:00
|
|
|
Print version information
|
|
|
|
";
|
2017-11-22 09:09:51 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static CUSTOM_HELP_SECTION: &str = "blorp 1.4
|
2018-04-04 03:27:57 +00:00
|
|
|
Will M.
|
|
|
|
does stuff
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS] --fake <some>:<val>
|
2018-04-04 03:27:57 +00:00
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-f, --fake <some>:<val> some help
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2018-04-04 03:27:57 +00:00
|
|
|
|
|
|
|
NETWORKING:
|
2021-09-24 15:58:39 +00:00
|
|
|
-n, --no-proxy Do not use system proxy settings
|
2021-10-14 18:14:43 +00:00
|
|
|
--port
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2018-04-04 03:27:57 +00:00
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static ISSUE_1487: &str = "test
|
2019-06-25 23:02:53 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest <arg1|arg2>
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<arg1>
|
|
|
|
<arg2>
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-10-08 17:05:40 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2019-06-25 23:02:53 +00:00
|
|
|
|
2020-04-16 15:21:41 +00:00
|
|
|
static ISSUE_1364: &str = "demo
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
demo [OPTIONS] [FILES]...
|
2020-04-16 15:21:41 +00:00
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<FILES>...
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-10-08 17:05:40 +00:00
|
|
|
-f
|
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2020-04-16 15:21:41 +00:00
|
|
|
|
2020-10-10 15:11:42 +00:00
|
|
|
static OPTION_USAGE_ORDER: &str = "order
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
order [OPTIONS]
|
2020-10-10 15:11:42 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-10-10 15:11:42 +00:00
|
|
|
-a
|
|
|
|
-b
|
|
|
|
-B
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2020-10-10 15:11:42 +00:00
|
|
|
-s
|
|
|
|
--select_file
|
|
|
|
--select_folder
|
2021-09-24 15:58:39 +00:00
|
|
|
-x
|
|
|
|
";
|
2020-10-10 15:11:42 +00:00
|
|
|
|
2021-06-20 15:28:50 +00:00
|
|
|
static ABOUT_IN_SUBCOMMANDS_LIST: &str = "about-in-subcommands-list
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
about-in-subcommands-list [SUBCOMMAND]
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-12-17 15:24:53 +00:00
|
|
|
-h, --help Print help information
|
2021-06-20 15:28:50 +00:00
|
|
|
|
|
|
|
SUBCOMMANDS:
|
2021-12-17 15:24:53 +00:00
|
|
|
help Print this message or the help of the given subcommand(s)
|
|
|
|
sub short about sub
|
2021-06-20 15:28:50 +00:00
|
|
|
";
|
|
|
|
|
2022-02-12 03:48:29 +00:00
|
|
|
fn setup() -> Command<'static> {
|
|
|
|
Command::new("test")
|
2016-01-13 17:03:27 +00:00
|
|
|
.author("Kevin K.")
|
|
|
|
.about("tests stuff")
|
|
|
|
.version("1.3")
|
2017-11-22 09:09:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 18:50:17 +00:00
|
|
|
fn empty_args() -> impl IntoIterator<Item = String> {
|
|
|
|
std::iter::empty()
|
|
|
|
}
|
|
|
|
|
2017-11-22 09:09:51 +00:00
|
|
|
#[test]
|
|
|
|
fn help_short() {
|
2018-10-19 20:42:13 +00:00
|
|
|
let m = setup().try_get_matches_from(vec!["myprog", "-h"]);
|
2016-01-13 17:03:27 +00:00
|
|
|
|
|
|
|
assert!(m.is_err());
|
2022-01-25 22:19:28 +00:00
|
|
|
assert_eq!(m.unwrap_err().kind(), ErrorKind::DisplayHelp);
|
2016-01-13 17:03:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_long() {
|
2018-10-19 20:42:13 +00:00
|
|
|
let m = setup().try_get_matches_from(vec!["myprog", "--help"]);
|
2016-01-13 17:03:27 +00:00
|
|
|
|
|
|
|
assert!(m.is_err());
|
2022-01-25 22:19:28 +00:00
|
|
|
assert_eq!(m.unwrap_err().kind(), ErrorKind::DisplayHelp);
|
2016-01-13 17:03:27 +00:00
|
|
|
}
|
2015-09-09 02:39:31 +00:00
|
|
|
|
2016-01-15 04:23:50 +00:00
|
|
|
#[test]
|
|
|
|
fn help_no_subcommand() {
|
2018-10-19 20:42:13 +00:00
|
|
|
let m = setup().try_get_matches_from(vec!["myprog", "help"]);
|
2016-01-15 04:23:50 +00:00
|
|
|
|
|
|
|
assert!(m.is_err());
|
2022-01-25 22:19:28 +00:00
|
|
|
assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument);
|
2016-01-15 04:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_subcommand() {
|
2017-11-22 09:09:51 +00:00
|
|
|
let m = setup()
|
2018-01-25 04:05:05 +00:00
|
|
|
.subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("test")
|
2018-01-25 04:05:05 +00:00
|
|
|
.about("tests things")
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(arg!(-v --verbose "with verbosity")),
|
2018-01-25 04:05:05 +00:00
|
|
|
)
|
2018-10-19 20:42:13 +00:00
|
|
|
.try_get_matches_from(vec!["myprog", "help"]);
|
2016-01-15 04:23:50 +00:00
|
|
|
|
|
|
|
assert!(m.is_err());
|
2022-01-25 22:19:28 +00:00
|
|
|
assert_eq!(m.unwrap_err().kind(), ErrorKind::DisplayHelp);
|
2016-01-15 04:23:50 +00:00
|
|
|
}
|
2017-11-22 09:09:51 +00:00
|
|
|
|
2022-04-30 01:25:05 +00:00
|
|
|
#[test]
|
|
|
|
fn help_multi_subcommand_error() {
|
|
|
|
let cmd = Command::new("ctest").subcommand(
|
|
|
|
Command::new("subcmd").subcommand(
|
|
|
|
Command::new("multi")
|
|
|
|
.about("tests subcommands")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.version("0.1")
|
|
|
|
.arg(arg!(
|
|
|
|
-f --flag "tests flags"
|
|
|
|
))
|
|
|
|
.arg(
|
|
|
|
arg!(
|
|
|
|
-o --option <scoption> "tests options"
|
|
|
|
)
|
|
|
|
.required(false)
|
|
|
|
.multiple_values(true)
|
|
|
|
.multiple_occurrences(true),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
let err = cmd
|
|
|
|
.try_get_matches_from(["ctest", "help", "subcmd", "multi", "foo"])
|
|
|
|
.unwrap_err();
|
|
|
|
|
|
|
|
static EXPECTED: &str = "error: The subcommand 'foo' wasn't recognized
|
|
|
|
|
|
|
|
USAGE:
|
2022-05-02 14:25:40 +00:00
|
|
|
ctest subcmd multi [OPTIONS]
|
2022-04-30 01:25:05 +00:00
|
|
|
|
|
|
|
For more information try --help
|
|
|
|
";
|
|
|
|
utils::assert_eq(EXPECTED, err.to_string());
|
|
|
|
}
|
|
|
|
|
2017-05-07 00:18:11 +00:00
|
|
|
#[test]
|
|
|
|
fn req_last_arg_usage() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("example")
|
2021-10-11 19:42:17 +00:00
|
|
|
.version("1.0")
|
|
|
|
.arg(
|
|
|
|
Arg::new("FIRST")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("First")
|
2021-10-11 19:42:17 +00:00
|
|
|
.multiple_values(true)
|
|
|
|
.required(true),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("SECOND")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Second")
|
2021-10-11 19:42:17 +00:00
|
|
|
.multiple_values(true)
|
|
|
|
.required(true)
|
|
|
|
.last(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "example --help", LAST_ARG_REQ_MULT, false);
|
2017-05-07 00:18:11 +00:00
|
|
|
}
|
2016-01-15 04:23:50 +00:00
|
|
|
|
2017-05-06 23:52:12 +00:00
|
|
|
#[test]
|
|
|
|
fn args_with_last_usage() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("flamegraph")
|
2017-05-06 23:52:12 +00:00
|
|
|
.version("0.1")
|
2022-02-10 17:51:40 +00:00
|
|
|
.trailing_var_arg(true)
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("verbose")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Prints out more stuff.")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('v')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("verbose")
|
2021-11-29 14:56:30 +00:00
|
|
|
.multiple_occurrences(true),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("timeout")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Timeout in seconds.")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('t')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("timeout")
|
2018-01-31 20:15:01 +00:00
|
|
|
.value_name("SECONDS"),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("frequency")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("The sampling frequency.")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('f')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("frequency")
|
2018-01-31 20:15:01 +00:00
|
|
|
.value_name("HERTZ"),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("binary path")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("The path of the binary to be profiled. for a binary.")
|
2018-01-25 04:05:05 +00:00
|
|
|
.value_name("BINFILE"),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("pass through args")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Any arguments you wish to pass to the being profiled.")
|
2021-11-29 14:56:30 +00:00
|
|
|
.takes_value(true)
|
|
|
|
.multiple_values(true)
|
|
|
|
.last(true)
|
2018-11-14 17:05:06 +00:00
|
|
|
.value_name("ARGS"),
|
2017-05-06 23:52:12 +00:00
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "flamegraph --help", LAST_ARG_USAGE, false);
|
2017-05-06 23:52:12 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 02:39:31 +00:00
|
|
|
#[test]
|
2016-05-09 03:20:50 +00:00
|
|
|
fn subcommand_short_help() {
|
2020-02-04 08:10:53 +00:00
|
|
|
let m = utils::complex_app().try_get_matches_from(vec!["clap-test", "subcmd", "-h"]);
|
2015-09-09 02:39:31 +00:00
|
|
|
|
2016-05-09 03:20:50 +00:00
|
|
|
assert!(m.is_err());
|
2022-01-25 22:19:28 +00:00
|
|
|
assert_eq!(m.unwrap_err().kind(), ErrorKind::DisplayHelp);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
2015-09-09 02:39:31 +00:00
|
|
|
|
2016-05-09 03:20:50 +00:00
|
|
|
#[test]
|
|
|
|
fn subcommand_long_help() {
|
2020-02-04 08:10:53 +00:00
|
|
|
let m = utils::complex_app().try_get_matches_from(vec!["clap-test", "subcmd", "--help"]);
|
2015-09-09 02:39:31 +00:00
|
|
|
|
2016-05-09 03:20:50 +00:00
|
|
|
assert!(m.is_err());
|
2022-01-25 22:19:28 +00:00
|
|
|
assert_eq!(m.unwrap_err().kind(), ErrorKind::DisplayHelp);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
2015-09-09 02:39:31 +00:00
|
|
|
|
2016-05-09 03:20:50 +00:00
|
|
|
#[test]
|
|
|
|
fn subcommand_help_rev() {
|
2020-02-04 08:10:53 +00:00
|
|
|
let m = utils::complex_app().try_get_matches_from(vec!["clap-test", "help", "subcmd"]);
|
2016-05-09 03:20:50 +00:00
|
|
|
|
|
|
|
assert!(m.is_err());
|
2022-01-25 22:19:28 +00:00
|
|
|
assert_eq!(m.unwrap_err().kind(), ErrorKind::DisplayHelp);
|
2015-09-09 02:39:31 +00:00
|
|
|
}
|
2016-02-02 08:13:43 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-05-09 03:20:50 +00:00
|
|
|
fn complex_help_output() {
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(utils::complex_app(), "clap-test --help", HELP, false);
|
2016-05-09 03:20:50 +00:00
|
|
|
}
|
2016-02-02 08:13:43 +00:00
|
|
|
|
2016-05-30 10:01:00 +00:00
|
|
|
#[test]
|
|
|
|
fn after_and_before_help_output() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("clap-test")
|
2016-05-30 10:01:00 +00:00
|
|
|
.version("v1.4.8")
|
|
|
|
.about("tests clap library")
|
|
|
|
.before_help("some text that comes before the help")
|
|
|
|
.after_help("some text that comes after the help");
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd.clone(), "clap-test -h", AFTER_HELP, false);
|
|
|
|
utils::assert_output(cmd, "clap-test --help", AFTER_HELP, false);
|
2016-05-30 10:01:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 15:06:57 +00:00
|
|
|
#[test]
|
|
|
|
fn after_and_before_long_help_output() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("clap-test")
|
2020-07-11 15:06:57 +00:00
|
|
|
.version("v1.4.8")
|
|
|
|
.about("tests clap library")
|
|
|
|
.before_help("some text that comes before the help")
|
|
|
|
.after_help("some text that comes after the help")
|
|
|
|
.before_long_help("some longer text that comes before the help")
|
|
|
|
.after_long_help("some longer text that comes after the help");
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd.clone(), "clap-test --help", AFTER_LONG_HELP, false);
|
|
|
|
utils::assert_output(cmd, "clap-test -h", AFTER_HELP, false);
|
2020-07-11 15:06:57 +00:00
|
|
|
}
|
|
|
|
|
2016-08-20 21:14:18 +00:00
|
|
|
#[test]
|
|
|
|
fn multi_level_sc_help() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("subcmd").subcommand(
|
|
|
|
Command::new("multi")
|
2018-01-25 04:05:05 +00:00
|
|
|
.about("tests subcommands")
|
|
|
|
.author("Kevin K. <kbknapp@gmail.com>")
|
|
|
|
.version("0.1")
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(arg!(
|
|
|
|
-f --flag "tests flags"
|
2021-11-18 20:17:31 +00:00
|
|
|
))
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(
|
|
|
|
arg!(
|
|
|
|
-o --option <scoption> "tests options"
|
|
|
|
)
|
|
|
|
.required(false)
|
|
|
|
.multiple_values(true)
|
|
|
|
.multiple_occurrences(true),
|
|
|
|
),
|
2018-01-25 04:05:05 +00:00
|
|
|
),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest help subcmd multi", MULTI_SC_HELP, false);
|
2016-08-20 21:14:18 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 23:35:16 +00:00
|
|
|
#[test]
|
|
|
|
fn no_wrap_help() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest")
|
2022-02-12 03:48:29 +00:00
|
|
|
.term_width(0)
|
|
|
|
.override_help(MULTI_SC_HELP);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", &format!("{}\n", MULTI_SC_HELP), false);
|
2016-08-24 23:35:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 23:19:08 +00:00
|
|
|
#[test]
|
|
|
|
fn no_wrap_default_help() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("1.0").term_width(0);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", DEFAULT_HELP, false);
|
2017-09-06 23:19:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 13:09:14 +00:00
|
|
|
#[test]
|
|
|
|
#[cfg(feature = "wrap_help")]
|
|
|
|
fn wrapped_help() {
|
|
|
|
static WRAPPED_HELP: &str = "test
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS]
|
2020-10-25 13:09:14 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-10-25 13:09:14 +00:00
|
|
|
-a, --all
|
|
|
|
Also do versioning for private crates (will not be
|
|
|
|
published)
|
|
|
|
|
|
|
|
--exact
|
|
|
|
Specify inter dependency version numbers exactly with
|
|
|
|
`=`
|
|
|
|
|
|
|
|
-h, --help
|
2021-07-30 03:23:25 +00:00
|
|
|
Print help information
|
2020-10-25 13:09:14 +00:00
|
|
|
|
|
|
|
--no-git-commit
|
|
|
|
Do not commit version changes
|
|
|
|
|
|
|
|
--no-git-push
|
|
|
|
Do not push generated commit and tags to git remote
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2020-10-25 13:09:14 +00:00
|
|
|
.term_width(67)
|
|
|
|
.arg(
|
|
|
|
Arg::new("all")
|
|
|
|
.short('a')
|
|
|
|
.long("all")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Also do versioning for private crates (will not be published)"),
|
2020-10-25 13:09:14 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("exact")
|
|
|
|
.long("exact")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Specify inter dependency version numbers exactly with `=`"),
|
2020-10-25 13:09:14 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("no_git_commit")
|
|
|
|
.long("no-git-commit")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Do not commit version changes"),
|
2020-10-25 13:09:14 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("no_git_push")
|
|
|
|
.long("no-git-push")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Do not push generated commit and tags to git remote"),
|
2020-10-25 13:09:14 +00:00
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", WRAPPED_HELP, false);
|
2020-10-25 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(feature = "wrap_help")]
|
|
|
|
fn unwrapped_help() {
|
|
|
|
static UNWRAPPED_HELP: &str = "test
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS]
|
2020-10-25 13:09:14 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-10-25 13:09:14 +00:00
|
|
|
-a, --all Also do versioning for private crates
|
|
|
|
(will not be published)
|
|
|
|
--exact Specify inter dependency version numbers
|
|
|
|
exactly with `=`
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2020-10-25 13:09:14 +00:00
|
|
|
--no-git-commit Do not commit version changes
|
|
|
|
--no-git-push Do not push generated commit and tags to
|
|
|
|
git remote
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2020-10-25 13:09:14 +00:00
|
|
|
.term_width(68)
|
|
|
|
.arg(
|
|
|
|
Arg::new("all")
|
|
|
|
.short('a')
|
|
|
|
.long("all")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Also do versioning for private crates (will not be published)"),
|
2020-10-25 13:09:14 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("exact")
|
|
|
|
.long("exact")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Specify inter dependency version numbers exactly with `=`"),
|
2020-10-25 13:09:14 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("no_git_commit")
|
|
|
|
.long("no-git-commit")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Do not commit version changes"),
|
2020-10-25 13:09:14 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("no_git_push")
|
|
|
|
.long("no-git-push")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Do not push generated commit and tags to git remote"),
|
2020-10-25 13:09:14 +00:00
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", UNWRAPPED_HELP, false);
|
2020-10-25 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:15:28 +00:00
|
|
|
#[test]
|
|
|
|
#[cfg(all(feature = "wrap_help"))]
|
|
|
|
fn possible_value_wrapped_help() {
|
|
|
|
#[cfg(feature = "unstable-v4")]
|
|
|
|
static WRAPPED_HELP: &str = "test
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h, --help
|
|
|
|
Print help information
|
|
|
|
|
|
|
|
--possible-values <possible_values>
|
|
|
|
Possible values:
|
|
|
|
- short_name:
|
|
|
|
Long enough help message, barely warrant wrapping
|
|
|
|
- second:
|
|
|
|
Short help gets handled the same
|
|
|
|
|
|
|
|
--possible-values-with-new-line <possible_values_with_new_line>
|
|
|
|
Possible values:
|
|
|
|
- long enough name to trigger new line:
|
|
|
|
Really long enough help message to clearly warrant
|
|
|
|
wrapping believe me
|
|
|
|
- second
|
|
|
|
|
|
|
|
--possible-values-without-new-line <possible_values_without_new_line>
|
|
|
|
Possible values:
|
|
|
|
- name: Short enough help message with no wrapping
|
|
|
|
- second: short help
|
|
|
|
";
|
|
|
|
#[cfg(not(feature = "unstable-v4"))]
|
|
|
|
static WRAPPED_HELP: &str = r#"test
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h, --help Print help information
|
|
|
|
--possible-values <possible_values> [possible values: short_name, second]
|
|
|
|
--possible-values-with-new-line <possible_values_with_new_line> [possible values: "long enough name to trigger new line", second]
|
|
|
|
--possible-values-without-new-line <possible_values_without_new_line> [possible values: name, second]
|
|
|
|
"#;
|
|
|
|
let cmd = Command::new("test")
|
|
|
|
.term_width(67)
|
|
|
|
.arg(
|
|
|
|
Arg::new("possible_values")
|
|
|
|
.long("possible-values")
|
|
|
|
.possible_value(
|
|
|
|
PossibleValue::new("short_name")
|
|
|
|
.help("Long enough help message, barely warrant wrapping"),
|
|
|
|
)
|
|
|
|
.possible_value(
|
|
|
|
PossibleValue::new("second").help("Short help gets handled the same"),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("possible_values_with_new_line")
|
|
|
|
.long("possible-values-with-new-line")
|
|
|
|
.possible_value(
|
|
|
|
PossibleValue::new("long enough name to trigger new line").help(
|
|
|
|
"Really long enough help message to clearly warrant wrapping believe me",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.possible_value("second"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("possible_values_without_new_line")
|
|
|
|
.long("possible-values-without-new-line")
|
|
|
|
.possible_value(
|
|
|
|
PossibleValue::new("name").help("Short enough help message with no wrapping"),
|
|
|
|
)
|
|
|
|
.possible_value(PossibleValue::new("second").help("short help")),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", WRAPPED_HELP, false);
|
2022-03-02 15:15:28 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 03:20:50 +00:00
|
|
|
#[test]
|
|
|
|
fn complex_subcommand_help_output() {
|
2020-02-04 08:10:53 +00:00
|
|
|
let a = utils::complex_app();
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(a, "clap-test subcmd --help", SC_HELP, false);
|
2016-02-02 08:13:43 +00:00
|
|
|
}
|
2016-08-25 01:50:20 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_626_unicode_cutoff() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").term_width(70).arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("cafe")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2017-02-21 04:51:20 +00:00
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help(
|
2018-01-25 04:05:05 +00:00
|
|
|
"A coffeehouse, coffee shop, or café is an establishment \
|
|
|
|
which primarily serves hot coffee, related coffee beverages \
|
|
|
|
(e.g., café latte, cappuccino, espresso), tea, and other hot \
|
|
|
|
beverages. Some coffeehouses also serve cold beverages such as \
|
|
|
|
iced coffee and iced tea. Many cafés also serve some type of \
|
|
|
|
food, such as light snacks, muffins, or pastries.",
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
|
|
|
.takes_value(true),
|
2018-01-25 04:05:05 +00:00
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", ISSUE_626_CUTOFF, false);
|
2016-08-25 01:50:20 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 03:08:40 +00:00
|
|
|
#[test]
|
|
|
|
fn hide_possible_vals() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest")
|
2016-09-11 03:08:40 +00:00
|
|
|
.version("0.1")
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("pos")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('p')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("pos")
|
|
|
|
.value_name("VAL")
|
2021-09-19 10:29:09 +00:00
|
|
|
.possible_values(["fast", "slow"])
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Some vals")
|
2018-01-25 04:05:05 +00:00
|
|
|
.takes_value(true),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("cafe")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
|
|
|
.hide_possible_values(true)
|
2021-09-19 10:29:09 +00:00
|
|
|
.possible_values(["fast", "slow"])
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café.")
|
2021-09-19 10:29:09 +00:00
|
|
|
.takes_value(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", HIDE_POS_VALS, false);
|
2021-09-19 10:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_single_possible_val() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest")
|
2021-09-19 10:29:09 +00:00
|
|
|
.version("0.1")
|
|
|
|
.arg(
|
|
|
|
Arg::new("pos")
|
|
|
|
.short('p')
|
|
|
|
.long("pos")
|
|
|
|
.value_name("VAL")
|
|
|
|
.possible_values(["fast", "slow"])
|
2021-11-29 16:45:30 +00:00
|
|
|
.possible_value(PossibleValue::new("secret speed").hide(true))
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Some vals")
|
2021-09-19 10:29:09 +00:00
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café.")
|
2018-01-25 04:05:05 +00:00
|
|
|
.takes_value(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", HIDE_POS_VALS, false);
|
2016-09-11 03:08:40 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:15:28 +00:00
|
|
|
#[test]
|
|
|
|
fn possible_vals_with_help() {
|
|
|
|
#[cfg(feature = "unstable-v4")]
|
|
|
|
static POS_VALS_HELP: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-c, --cafe <FILE>
|
|
|
|
A coffeehouse, coffee shop, or café.
|
|
|
|
|
|
|
|
-h, --help
|
|
|
|
Print help information
|
|
|
|
|
|
|
|
-p, --pos <VAL>
|
|
|
|
Some vals
|
|
|
|
|
|
|
|
Possible values:
|
|
|
|
- fast
|
|
|
|
- slow: not as fast
|
|
|
|
|
|
|
|
-V, --version
|
|
|
|
Print version information
|
|
|
|
";
|
|
|
|
#[cfg(not(feature = "unstable-v4"))]
|
|
|
|
static POS_VALS_HELP: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café.
|
|
|
|
-h, --help Print help information
|
|
|
|
-p, --pos <VAL> Some vals [possible values: fast, slow]
|
|
|
|
-V, --version Print version information
|
|
|
|
";
|
|
|
|
let app = Command::new("ctest")
|
|
|
|
.version("0.1")
|
|
|
|
.arg(
|
|
|
|
Arg::new("pos")
|
|
|
|
.short('p')
|
|
|
|
.long("pos")
|
|
|
|
.value_name("VAL")
|
|
|
|
.possible_value("fast")
|
|
|
|
.possible_value(PossibleValue::new("slow").help("not as fast"))
|
|
|
|
.possible_value(PossibleValue::new("secret speed").hide(true))
|
|
|
|
.help("Some vals")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
|
|
|
.help("A coffeehouse, coffee shop, or café.")
|
|
|
|
.takes_value(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(app, "ctest --help", POS_VALS_HELP, false);
|
2022-03-02 15:15:28 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 01:50:20 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_626_panic() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest")
|
2016-08-25 01:50:20 +00:00
|
|
|
.version("0.1")
|
2020-05-18 07:51:36 +00:00
|
|
|
.term_width(52)
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("cafe")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2016-08-25 01:50:20 +00:00
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("La culture du café est très développée dans de nombreux pays à climat chaud d'Amérique, \
|
2016-08-25 01:50:20 +00:00
|
|
|
d'Afrique et d'Asie, dans des plantations qui sont cultivées pour les marchés d'exportation. \
|
|
|
|
Le café est souvent une contribution majeure aux exportations des régions productrices.")
|
|
|
|
.takes_value(true));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", ISSUE_626_PANIC, false);
|
2016-08-25 01:50:20 +00:00
|
|
|
}
|
2016-08-25 22:50:48 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_626_variable_panic() {
|
|
|
|
for i in 10..320 {
|
2022-02-12 03:48:29 +00:00
|
|
|
let _ = Command::new("ctest")
|
2016-08-25 22:50:48 +00:00
|
|
|
.version("0.1")
|
2020-05-18 07:51:36 +00:00
|
|
|
.term_width(i)
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("cafe")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('c')
|
2016-08-25 22:50:48 +00:00
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("La culture du café est très développée dans de nombreux pays à climat chaud d'Amérique, \
|
2016-08-25 22:50:48 +00:00
|
|
|
d'Afrique et d'Asie, dans des plantations qui sont cultivées pour les marchés d'exportation. \
|
|
|
|
Le café est souvent une contribution majeure aux exportations des régions productrices.")
|
|
|
|
.takes_value(true))
|
2018-10-19 20:42:13 +00:00
|
|
|
.try_get_matches_from(vec!["ctest", "--help"]);
|
2016-08-25 22:50:48 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-13 03:20:40 +00:00
|
|
|
|
2017-01-29 19:54:47 +00:00
|
|
|
#[test]
|
|
|
|
fn final_word_wrapping() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").term_width(24);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", FINAL_WORD_WRAPPING, false);
|
2017-01-29 19:54:47 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 20:38:30 +00:00
|
|
|
#[test]
|
|
|
|
fn wrapping_newline_chars() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest")
|
2020-05-14 20:50:56 +00:00
|
|
|
.version("0.1")
|
2020-05-18 07:51:36 +00:00
|
|
|
.term_width(60)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("mode").help(
|
2020-05-14 20:50:56 +00:00
|
|
|
"x, max, maximum 20 characters, contains symbols.\n\
|
2020-04-12 01:36:20 +00:00
|
|
|
l, long Copy-friendly, 14 characters, contains symbols.\n\
|
|
|
|
m, med, medium Copy-friendly, 8 characters, contains symbols.\n",
|
2020-05-14 20:50:56 +00:00
|
|
|
));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", WRAPPING_NEWLINE_CHARS, false);
|
2017-01-29 20:38:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 17:08:53 +00:00
|
|
|
#[test]
|
|
|
|
fn wrapping_newline_variables() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest")
|
2021-12-30 17:08:53 +00:00
|
|
|
.version("0.1")
|
|
|
|
.term_width(60)
|
|
|
|
.arg(Arg::new("mode").help(
|
|
|
|
"x, max, maximum 20 characters, contains symbols.{n}\
|
|
|
|
l, long Copy-friendly, 14 characters, contains symbols.{n}\
|
|
|
|
m, med, medium Copy-friendly, 8 characters, contains symbols.{n}",
|
|
|
|
));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", WRAPPING_NEWLINE_CHARS, false);
|
2021-12-30 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
2016-09-13 03:20:40 +00:00
|
|
|
#[test]
|
|
|
|
fn old_newline_chars() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("mode")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('m')
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Some help with some wrapping\n(Defaults to something)"),
|
2018-01-25 04:05:05 +00:00
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", OLD_NEWLINE_CHARS, false);
|
2016-09-13 03:20:40 +00:00
|
|
|
}
|
2016-10-20 23:37:39 +00:00
|
|
|
|
2021-12-30 17:08:53 +00:00
|
|
|
#[test]
|
|
|
|
fn old_newline_variables() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2021-12-30 17:08:53 +00:00
|
|
|
Arg::new("mode")
|
|
|
|
.short('m')
|
|
|
|
.help("Some help with some wrapping{n}(Defaults to something)"),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", OLD_NEWLINE_CHARS, false);
|
2021-12-30 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 23:37:39 +00:00
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn issue_688_hide_pos_vals() {
|
2017-02-21 04:51:20 +00:00
|
|
|
let filter_values = ["Nearest", "Linear", "Cubic", "Gaussian", "Lanczos3"];
|
2016-10-20 23:37:39 +00:00
|
|
|
|
2022-02-12 03:48:29 +00:00
|
|
|
let app1 = Command::new("ctest")
|
2016-10-20 23:37:39 +00:00
|
|
|
.version("0.1")
|
2020-05-18 07:51:36 +00:00
|
|
|
.term_width(120)
|
2022-02-10 17:51:40 +00:00
|
|
|
.hide_possible_values(true)
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("filter")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Sets the filter, or sampling method, to use for interpolation when resizing the particle \
|
2018-02-12 19:52:29 +00:00
|
|
|
images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic, Gaussian, Lanczos3]")
|
2016-10-20 23:37:39 +00:00
|
|
|
.long("filter")
|
2021-09-19 10:29:09 +00:00
|
|
|
.possible_values(filter_values)
|
2016-10-20 23:37:39 +00:00
|
|
|
.takes_value(true));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(app1, "ctest --help", ISSUE_688, false);
|
2016-10-20 23:37:39 +00:00
|
|
|
|
2022-02-12 03:48:29 +00:00
|
|
|
let app2 = Command::new("ctest")
|
2016-10-20 23:37:39 +00:00
|
|
|
.version("0.1")
|
2020-05-18 07:51:36 +00:00
|
|
|
.term_width(120)
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("filter")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Sets the filter, or sampling method, to use for interpolation when resizing the particle \
|
2016-10-20 23:37:39 +00:00
|
|
|
images. The default is Linear (Bilinear).")
|
|
|
|
.long("filter")
|
2021-09-19 10:29:09 +00:00
|
|
|
.possible_values(filter_values)
|
2016-10-20 23:37:39 +00:00
|
|
|
.takes_value(true));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(app2, "ctest --help", ISSUE_688, false);
|
2016-10-20 23:37:39 +00:00
|
|
|
|
2022-02-12 03:48:29 +00:00
|
|
|
let app3 = Command::new("ctest")
|
2016-10-20 23:37:39 +00:00
|
|
|
.version("0.1")
|
2020-05-18 07:51:36 +00:00
|
|
|
.term_width(120)
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("filter")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Sets the filter, or sampling method, to use for interpolation when resizing the particle \
|
2018-02-12 19:52:29 +00:00
|
|
|
images. The default is Linear (Bilinear). [possible values: Nearest, Linear, Cubic, Gaussian, Lanczos3]")
|
2016-10-20 23:37:39 +00:00
|
|
|
.long("filter")
|
|
|
|
.takes_value(true));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(app3, "ctest --help", ISSUE_688, false);
|
2016-10-24 09:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_702_multiple_values() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("myapp")
|
2016-10-24 09:56:21 +00:00
|
|
|
.version("1.0")
|
|
|
|
.author("foo")
|
|
|
|
.about("bar")
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("arg1").help("some option"))
|
2021-02-24 15:07:57 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("arg2")
|
|
|
|
.takes_value(true)
|
2021-06-16 05:28:25 +00:00
|
|
|
.multiple_values(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("some option"),
|
2021-02-24 15:07:57 +00:00
|
|
|
)
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("some")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("some option")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('s')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("some")
|
|
|
|
.takes_value(true),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("other")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("some other option")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('o')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("other")
|
|
|
|
.takes_value(true),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("label")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("a label")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('l')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("label")
|
2021-06-16 05:28:25 +00:00
|
|
|
.multiple_values(true)
|
2018-01-25 04:05:05 +00:00
|
|
|
.takes_value(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "myapp --help", ISSUE_702, false);
|
2016-12-01 23:47:20 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 18:41:49 +00:00
|
|
|
#[test]
|
|
|
|
fn long_about() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("myapp")
|
2017-09-13 18:41:49 +00:00
|
|
|
.version("1.0")
|
|
|
|
.author("foo")
|
|
|
|
.about("bar")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long_about(
|
|
|
|
"something really really long, with\nmultiple lines of text\nthat should be displayed",
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("arg1").help("some option"));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "myapp --help", LONG_ABOUT, false);
|
2017-09-13 18:41:49 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 23:47:20 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_760() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest")
|
2016-12-01 23:47:20 +00:00
|
|
|
.version("0.1")
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("option")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("tests options")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('o')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("option")
|
|
|
|
.takes_value(true)
|
2021-06-16 05:28:25 +00:00
|
|
|
.multiple_values(true)
|
2018-01-25 04:05:05 +00:00
|
|
|
.number_of_values(1),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("opt")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("tests options")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('O')
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("opt")
|
|
|
|
.takes_value(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", ISSUE_760, false);
|
2017-01-02 21:44:40 +00:00
|
|
|
}
|
2017-03-09 13:52:37 +00:00
|
|
|
|
2021-08-17 09:17:18 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_1571() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("hello").arg(
|
2021-08-17 09:17:18 +00:00
|
|
|
Arg::new("name")
|
|
|
|
.long("package")
|
|
|
|
.short('p')
|
|
|
|
.number_of_values(1)
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple_values(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-08-17 09:17:18 +00:00
|
|
|
"hello --help",
|
|
|
|
"hello
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
hello [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-p, --package <name>
|
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-08-17 09:17:18 +00:00
|
|
|
}
|
|
|
|
|
2017-03-24 03:51:43 +00:00
|
|
|
#[test]
|
|
|
|
fn ripgrep_usage() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ripgrep").version("0.5").override_usage(
|
2018-01-25 04:05:05 +00:00
|
|
|
"rg [OPTIONS] <pattern> [<path> ...]
|
2017-03-24 03:51:43 +00:00
|
|
|
rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
|
|
|
|
rg [OPTIONS] --files [<path> ...]
|
2018-01-25 04:05:05 +00:00
|
|
|
rg [OPTIONS] --type-list",
|
|
|
|
);
|
2017-03-24 03:51:43 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "rg --help", RIPGREP_USAGE, false);
|
2017-03-30 17:30:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ripgrep_usage_using_templates() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ripgrep")
|
2017-03-30 17:30:23 +00:00
|
|
|
.version("0.5")
|
2018-10-19 20:42:13 +00:00
|
|
|
.override_usage(
|
2018-01-25 04:05:05 +00:00
|
|
|
"
|
2017-03-30 17:30:23 +00:00
|
|
|
rg [OPTIONS] <pattern> [<path> ...]
|
|
|
|
rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
|
|
|
|
rg [OPTIONS] --files [<path> ...]
|
2018-01-25 04:05:05 +00:00
|
|
|
rg [OPTIONS] --type-list",
|
|
|
|
)
|
2018-10-19 20:42:13 +00:00
|
|
|
.help_template(
|
2018-01-25 04:05:05 +00:00
|
|
|
"\
|
2017-03-30 17:30:23 +00:00
|
|
|
{bin} {version}
|
|
|
|
|
|
|
|
USAGE:{usage}
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
|
|
|
{options}",
|
2018-01-25 04:05:05 +00:00
|
|
|
);
|
2017-03-30 17:30:23 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "rg --help", RIPGREP_USAGE, false);
|
2017-03-24 03:51:43 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 13:52:37 +00:00
|
|
|
#[test]
|
|
|
|
fn sc_negates_reqs() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("prog")
|
2017-03-09 13:52:37 +00:00
|
|
|
.version("1.0")
|
2022-02-10 17:51:40 +00:00
|
|
|
.subcommand_negates_reqs(true)
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(arg!(-o --opt <FILE> "tests options"))
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("PATH").help("help"))
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("test"));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "prog --help", SC_NEGATES_REQS, false);
|
2017-03-09 13:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-22 09:09:51 +00:00
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_args() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("prog")
|
2017-11-22 09:09:51 +00:00
|
|
|
.version("1.0")
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(arg!(-f --flag "testing flags"))
|
|
|
|
.arg(arg!(-o --opt <FILE> "tests options").required(false))
|
2021-11-29 16:45:30 +00:00
|
|
|
.arg(Arg::new("pos").hide(true));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "prog --help", HIDDEN_ARGS, false);
|
2017-11-22 09:09:51 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 13:52:37 +00:00
|
|
|
#[test]
|
|
|
|
fn args_negate_sc() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("prog")
|
2017-03-09 13:52:37 +00:00
|
|
|
.version("1.0")
|
2022-02-10 17:51:40 +00:00
|
|
|
.args_conflicts_with_subcommands(true)
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(arg!(-f --flag "testing flags"))
|
|
|
|
.arg(arg!(-o --opt <FILE> "tests options").required(false))
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("PATH").help("help"))
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("test"));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "prog --help", ARGS_NEGATE_SC, false);
|
2017-03-09 13:52:37 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 17:37:13 +00:00
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn issue_1046_hide_scs() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("prog")
|
2017-09-14 17:37:13 +00:00
|
|
|
.version("1.0")
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(arg!(-f --flag "testing flags"))
|
|
|
|
.arg(arg!(-o --opt <FILE> "tests options").required(false))
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("PATH").help("some"))
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("test").hide(true));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "prog --help", ISSUE_1046_HIDDEN_SCS, false);
|
2017-09-14 17:37:13 +00:00
|
|
|
}
|
|
|
|
|
2017-01-02 21:44:40 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_777_wrap_all_things() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("A cmd with a crazy very long long long name hahaha")
|
2017-01-02 21:44:40 +00:00
|
|
|
.version("1.0")
|
|
|
|
.author("Some Very Long Name and crazy long email <email@server.com>")
|
|
|
|
.about("Show how the about text is not wrapped")
|
2020-05-18 07:51:36 +00:00
|
|
|
.term_width(35);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", ISSUE_777, false);
|
2017-01-08 11:51:20 +00:00
|
|
|
}
|
2017-03-10 06:01:32 +00:00
|
|
|
|
2020-10-26 08:37:45 +00:00
|
|
|
static OVERRIDE_HELP_SHORT: &str = "test 0.1
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-H, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2020-10-26 08:37:45 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn override_help_short() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2020-10-26 08:37:45 +00:00
|
|
|
.version("0.1")
|
|
|
|
.mut_arg("help", |h| h.short('H'));
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd.clone(), "test --help", OVERRIDE_HELP_SHORT, false);
|
|
|
|
utils::assert_output(cmd, "test -H", OVERRIDE_HELP_SHORT, false);
|
2020-10-26 08:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static OVERRIDE_HELP_LONG: &str = "test 0.1
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS]
|
2020-10-26 08:37:45 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --hell Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2020-10-26 08:37:45 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn override_help_long() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2020-10-26 08:37:45 +00:00
|
|
|
.version("0.1")
|
|
|
|
.mut_arg("help", |h| h.long("hell"));
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd.clone(), "test --hell", OVERRIDE_HELP_LONG, false);
|
|
|
|
utils::assert_output(cmd, "test -h", OVERRIDE_HELP_LONG, false);
|
2020-10-26 08:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static OVERRIDE_HELP_ABOUT: &str = "test 0.1
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-10-26 08:37:45 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2020-10-26 08:37:45 +00:00
|
|
|
|
2017-03-10 06:01:32 +00:00
|
|
|
#[test]
|
2020-10-26 08:37:45 +00:00
|
|
|
fn override_help_about() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2017-03-10 06:01:32 +00:00
|
|
|
.version("0.1")
|
2021-11-18 16:17:15 +00:00
|
|
|
.mut_arg("help", |h| h.help("Print help information"));
|
2020-10-26 08:37:45 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd.clone(), "test --help", OVERRIDE_HELP_ABOUT, false);
|
|
|
|
utils::assert_output(cmd, "test -h", OVERRIDE_HELP_ABOUT, false);
|
2017-03-10 06:01:32 +00:00
|
|
|
}
|
2017-03-11 05:17:57 +00:00
|
|
|
|
2020-04-08 20:26:05 +00:00
|
|
|
#[test]
|
|
|
|
fn arg_short_conflict_with_help() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("conflict").arg(Arg::new("home").short('h'));
|
2020-04-08 20:26:05 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "conflict --help", HELP_CONFLICT, false);
|
2020-04-08 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 16:19:05 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2020-04-08 20:26:05 +00:00
|
|
|
#[test]
|
2022-02-09 00:44:46 +00:00
|
|
|
#[should_panic = "`help`s `-h` conflicts with `home`."]
|
2020-04-08 20:26:05 +00:00
|
|
|
fn arg_short_conflict_with_help_mut_arg() {
|
2022-02-12 03:48:29 +00:00
|
|
|
let _ = Command::new("conflict")
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("home").short('h'))
|
2020-04-08 20:26:05 +00:00
|
|
|
.mut_arg("help", |h| h.short('h'))
|
|
|
|
.try_get_matches_from(vec![""]);
|
|
|
|
}
|
|
|
|
|
2017-03-11 05:17:57 +00:00
|
|
|
#[test]
|
|
|
|
fn last_arg_mult_usage() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("last")
|
2018-01-25 04:05:05 +00:00
|
|
|
.version("0.1")
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("TARGET").required(true).help("some"))
|
|
|
|
.arg(Arg::new("CORPUS").help("some"))
|
2021-02-24 15:07:57 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("ARGS")
|
|
|
|
.takes_value(true)
|
2021-06-16 05:28:25 +00:00
|
|
|
.multiple_values(true)
|
2021-02-24 15:07:57 +00:00
|
|
|
.last(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("some"),
|
2021-02-24 15:07:57 +00:00
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "last --help", LAST_ARG, false);
|
2017-03-11 05:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn last_arg_mult_usage_req() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("last")
|
2018-01-25 04:05:05 +00:00
|
|
|
.version("0.1")
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("TARGET").required(true).help("some"))
|
|
|
|
.arg(Arg::new("CORPUS").help("some"))
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("ARGS")
|
2021-02-24 15:07:57 +00:00
|
|
|
.takes_value(true)
|
2021-06-16 05:28:25 +00:00
|
|
|
.multiple_values(true)
|
2018-01-25 04:05:05 +00:00
|
|
|
.last(true)
|
|
|
|
.required(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("some"),
|
2018-01-25 04:05:05 +00:00
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "last --help", LAST_ARG_REQ, false);
|
2017-03-11 05:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn last_arg_mult_usage_req_with_sc() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("last")
|
2018-01-25 04:05:05 +00:00
|
|
|
.version("0.1")
|
2022-02-10 17:51:40 +00:00
|
|
|
.subcommand_negates_reqs(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("TARGET").required(true).help("some"))
|
|
|
|
.arg(Arg::new("CORPUS").help("some"))
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("ARGS")
|
2021-02-24 15:07:57 +00:00
|
|
|
.takes_value(true)
|
2021-06-16 05:28:25 +00:00
|
|
|
.multiple_values(true)
|
2018-01-25 04:05:05 +00:00
|
|
|
.last(true)
|
|
|
|
.required(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("some"),
|
2018-01-25 04:05:05 +00:00
|
|
|
)
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("test").about("some"));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "last --help", LAST_ARG_REQ_SC, false);
|
2017-03-11 05:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn last_arg_mult_usage_with_sc() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("last")
|
2018-01-25 04:05:05 +00:00
|
|
|
.version("0.1")
|
2022-02-10 17:51:40 +00:00
|
|
|
.args_conflicts_with_subcommands(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("TARGET").required(true).help("some"))
|
|
|
|
.arg(Arg::new("CORPUS").help("some"))
|
2021-02-24 15:07:57 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("ARGS")
|
|
|
|
.takes_value(true)
|
2021-06-16 05:28:25 +00:00
|
|
|
.multiple_values(true)
|
2021-02-24 15:07:57 +00:00
|
|
|
.last(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("some"),
|
2021-02-24 15:07:57 +00:00
|
|
|
)
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("test").about("some"));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "last --help", LAST_ARG_SC, false);
|
2017-03-22 10:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn hide_default_val() {
|
2022-02-12 03:48:29 +00:00
|
|
|
let app1 = Command::new("default").version("0.1").term_width(120).arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("argument")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Pass an argument to the program. [default: default-argument]")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("arg")
|
|
|
|
.default_value("default-argument")
|
|
|
|
.hide_default_value(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(app1, "default --help", HIDE_DEFAULT_VAL, false);
|
2018-01-25 04:05:05 +00:00
|
|
|
|
2022-02-12 03:48:29 +00:00
|
|
|
let app2 = Command::new("default").version("0.1").term_width(120).arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("argument")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Pass an argument to the program.")
|
2018-01-25 04:05:05 +00:00
|
|
|
.long("arg")
|
|
|
|
.default_value("default-argument"),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(app2, "default --help", HIDE_DEFAULT_VAL, false);
|
2017-03-22 10:14:02 +00:00
|
|
|
}
|
2017-04-04 23:54:20 +00:00
|
|
|
|
2020-09-23 08:45:14 +00:00
|
|
|
#[test]
|
|
|
|
fn escaped_whitespace_values() {
|
2022-02-12 03:48:29 +00:00
|
|
|
let app1 = Command::new("default").version("0.1").term_width(120).arg(
|
2020-09-23 08:45:14 +00:00
|
|
|
Arg::new("argument")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Pass an argument to the program.")
|
2020-09-23 08:45:14 +00:00
|
|
|
.long("arg")
|
|
|
|
.default_value("\n")
|
2021-09-19 10:29:09 +00:00
|
|
|
.possible_values(["normal", " ", "\n", "\t", "other"]),
|
2020-09-23 08:45:14 +00:00
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(app1, "default --help", ESCAPED_DEFAULT_VAL, false);
|
2020-09-23 08:45:14 +00:00
|
|
|
}
|
|
|
|
|
2022-02-12 03:48:29 +00:00
|
|
|
fn issue_1112_setup() -> Command<'static> {
|
|
|
|
Command::new("test")
|
2017-04-04 23:54:20 +00:00
|
|
|
.version("1.3")
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("help1").long("help").short('h').help("some help"))
|
2021-02-07 11:58:43 +00:00
|
|
|
.subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("foo").arg(Arg::new("help1").long("help").short('h').help("some help")),
|
2021-02-07 11:58:43 +00:00
|
|
|
)
|
2017-11-22 09:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-02-07 11:58:43 +00:00
|
|
|
fn prefer_user_help_long_1112() {
|
2018-10-19 20:42:13 +00:00
|
|
|
let m = issue_1112_setup().try_get_matches_from(vec!["test", "--help"]);
|
2017-04-04 23:54:20 +00:00
|
|
|
|
2021-12-27 19:57:38 +00:00
|
|
|
assert!(m.is_ok(), "{}", m.unwrap_err());
|
2021-02-07 11:58:43 +00:00
|
|
|
assert!(m.unwrap().is_present("help1"));
|
2017-05-11 15:17:28 +00:00
|
|
|
}
|
2017-10-12 22:11:51 +00:00
|
|
|
|
2017-11-22 09:09:51 +00:00
|
|
|
#[test]
|
2021-02-07 11:58:43 +00:00
|
|
|
fn prefer_user_help_short_1112() {
|
2018-10-19 20:42:13 +00:00
|
|
|
let m = issue_1112_setup().try_get_matches_from(vec!["test", "-h"]);
|
2017-11-22 09:09:51 +00:00
|
|
|
|
2021-12-27 19:57:38 +00:00
|
|
|
assert!(m.is_ok(), "{}", m.unwrap_err());
|
2021-02-07 11:58:43 +00:00
|
|
|
assert!(m.unwrap().is_present("help1"));
|
2017-11-22 09:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-02-07 11:58:43 +00:00
|
|
|
fn prefer_user_subcmd_help_long_1112() {
|
2018-10-19 20:42:13 +00:00
|
|
|
let m = issue_1112_setup().try_get_matches_from(vec!["test", "foo", "--help"]);
|
2017-11-22 09:09:51 +00:00
|
|
|
|
2021-12-27 19:57:38 +00:00
|
|
|
assert!(m.is_ok(), "{}", m.unwrap_err());
|
2018-11-14 17:05:06 +00:00
|
|
|
assert!(m
|
|
|
|
.unwrap()
|
|
|
|
.subcommand_matches("foo")
|
|
|
|
.unwrap()
|
2021-02-07 11:58:43 +00:00
|
|
|
.is_present("help1"));
|
2017-11-22 09:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-02-07 11:58:43 +00:00
|
|
|
fn prefer_user_subcmd_help_short_1112() {
|
2018-10-19 20:42:13 +00:00
|
|
|
let m = issue_1112_setup().try_get_matches_from(vec!["test", "foo", "-h"]);
|
2017-11-22 09:09:51 +00:00
|
|
|
|
2021-12-27 19:57:38 +00:00
|
|
|
assert!(m.is_ok(), "{}", m.unwrap_err());
|
2018-11-14 17:05:06 +00:00
|
|
|
assert!(m
|
|
|
|
.unwrap()
|
|
|
|
.subcommand_matches("foo")
|
|
|
|
.unwrap()
|
2021-02-07 11:58:43 +00:00
|
|
|
.is_present("help1"));
|
2017-11-22 09:09:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 22:11:51 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_1052_require_delim_help() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2017-10-12 22:11:51 +00:00
|
|
|
.author("Kevin K.")
|
|
|
|
.about("tests stuff")
|
|
|
|
.version("1.3")
|
2018-01-25 04:05:05 +00:00
|
|
|
.arg(
|
2021-11-19 20:33:11 +00:00
|
|
|
arg!(-f --fake "some help")
|
|
|
|
.required(true)
|
|
|
|
.value_names(&["some", "val"])
|
2021-02-24 15:07:57 +00:00
|
|
|
.takes_value(true)
|
2022-02-09 17:16:34 +00:00
|
|
|
.use_value_delimiter(true)
|
|
|
|
.require_value_delimiter(true)
|
2021-08-13 18:54:56 +00:00
|
|
|
.value_delimiter(':'),
|
2018-01-25 04:05:05 +00:00
|
|
|
);
|
2017-10-12 22:11:51 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", REQUIRE_DELIM_HELP, false);
|
2017-10-12 22:11:51 +00:00
|
|
|
}
|
2017-12-02 19:21:30 +00:00
|
|
|
|
2018-04-04 03:27:57 +00:00
|
|
|
#[test]
|
|
|
|
fn custom_headers_headers() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("blorp")
|
2018-04-04 03:27:57 +00:00
|
|
|
.author("Will M.")
|
|
|
|
.about("does stuff")
|
|
|
|
.version("1.4")
|
2018-07-23 19:09:42 +00:00
|
|
|
.arg(
|
2021-11-19 20:33:11 +00:00
|
|
|
arg!(-f --fake "some help")
|
|
|
|
.required(true)
|
|
|
|
.value_names(&["some", "val"])
|
2021-02-24 15:07:57 +00:00
|
|
|
.takes_value(true)
|
2022-02-09 17:16:34 +00:00
|
|
|
.use_value_delimiter(true)
|
|
|
|
.require_value_delimiter(true)
|
2021-08-13 18:54:56 +00:00
|
|
|
.value_delimiter(':'),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(Some("NETWORKING"))
|
2018-07-23 19:09:42 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("no-proxy")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('n')
|
2018-04-04 03:27:57 +00:00
|
|
|
.long("no-proxy")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Do not use system proxy settings"),
|
2021-10-14 18:14:43 +00:00
|
|
|
)
|
|
|
|
.args(&[Arg::new("port").long("port")]);
|
2018-04-04 03:27:57 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", CUSTOM_HELP_SECTION, false);
|
2018-04-04 03:27:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static MULTIPLE_CUSTOM_HELP_SECTIONS: &str = "blorp 1.4
|
2018-04-04 03:27:57 +00:00
|
|
|
Will M.
|
|
|
|
does stuff
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS] --fake <some>:<val> --birthday-song <song> --birthday-song-volume <volume>
|
2018-04-04 03:27:57 +00:00
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-f, --fake <some>:<val> some help
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
2018-04-04 03:27:57 +00:00
|
|
|
-s, --speed <SPEED> How fast? [possible values: fast, slow]
|
2021-10-14 17:16:20 +00:00
|
|
|
--style <style> Choose musical style to play the song
|
2021-10-11 22:01:33 +00:00
|
|
|
-V, --version Print version information
|
2018-04-04 03:27:57 +00:00
|
|
|
|
|
|
|
NETWORKING:
|
2020-06-01 06:04:41 +00:00
|
|
|
-a, --server-addr Set server address
|
2020-10-10 15:11:42 +00:00
|
|
|
-n, --no-proxy Do not use system proxy settings
|
2018-04-04 03:27:57 +00:00
|
|
|
|
2021-10-14 17:16:20 +00:00
|
|
|
OVERRIDE SPECIAL:
|
|
|
|
-b, --birthday-song <song> Change which song is played for birthdays
|
|
|
|
|
2018-04-04 03:27:57 +00:00
|
|
|
SPECIAL:
|
2021-09-24 15:58:39 +00:00
|
|
|
-v, --birthday-song-volume <volume> Change the volume of the birthday song
|
|
|
|
";
|
2018-04-04 03:27:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_custom_help_headers() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("blorp")
|
2018-04-04 03:27:57 +00:00
|
|
|
.author("Will M.")
|
|
|
|
.about("does stuff")
|
|
|
|
.version("1.4")
|
2018-07-23 19:09:42 +00:00
|
|
|
.arg(
|
2021-11-19 20:33:11 +00:00
|
|
|
arg!(-f --fake "some help")
|
|
|
|
.required(true)
|
|
|
|
.value_names(&["some", "val"])
|
2021-02-24 15:07:57 +00:00
|
|
|
.takes_value(true)
|
2022-02-09 17:16:34 +00:00
|
|
|
.use_value_delimiter(true)
|
|
|
|
.require_value_delimiter(true)
|
2021-08-13 18:54:56 +00:00
|
|
|
.value_delimiter(':'),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(Some("NETWORKING"))
|
2018-07-23 19:09:42 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("no-proxy")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('n')
|
2018-04-04 03:27:57 +00:00
|
|
|
.long("no-proxy")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Do not use system proxy settings"),
|
2018-11-14 17:05:06 +00:00
|
|
|
)
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(Some("SPECIAL"))
|
2020-06-01 06:04:41 +00:00
|
|
|
.arg(
|
2021-11-19 20:33:11 +00:00
|
|
|
arg!(-b --"birthday-song" <song> "Change which song is played for birthdays")
|
|
|
|
.help_heading(Some("OVERRIDE SPECIAL")),
|
2020-06-01 06:04:41 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2021-11-19 20:33:11 +00:00
|
|
|
arg!(--style <style> "Choose musical style to play the song")
|
2021-10-14 17:16:20 +00:00
|
|
|
.required(false)
|
|
|
|
.help_heading(None),
|
2020-06-01 06:04:41 +00:00
|
|
|
)
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(arg!(
|
|
|
|
-v --"birthday-song-volume" <volume> "Change the volume of the birthday song"
|
2021-10-14 17:16:20 +00:00
|
|
|
))
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(None)
|
2020-06-01 06:04:41 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("server-addr")
|
|
|
|
.short('a')
|
|
|
|
.long("server-addr")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Set server address")
|
2020-06-01 06:04:41 +00:00
|
|
|
.help_heading(Some("NETWORKING")),
|
|
|
|
)
|
2018-07-23 19:09:42 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("speed")
|
2018-04-04 03:27:57 +00:00
|
|
|
.long("speed")
|
2018-07-23 19:09:42 +00:00
|
|
|
.short('s')
|
2018-04-04 03:27:57 +00:00
|
|
|
.value_name("SPEED")
|
2021-09-19 10:29:09 +00:00
|
|
|
.possible_values(["fast", "slow"])
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("How fast?")
|
2018-07-23 19:09:42 +00:00
|
|
|
.takes_value(true),
|
|
|
|
);
|
2018-04-04 03:27:57 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", MULTIPLE_CUSTOM_HELP_SECTIONS, false);
|
2018-06-12 14:01:42 +00:00
|
|
|
}
|
|
|
|
|
2021-06-12 03:20:56 +00:00
|
|
|
static CUSTOM_HELP_SECTION_HIDDEN_ARGS: &str = "blorp 1.4
|
|
|
|
Will M.
|
|
|
|
does stuff
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
test [OPTIONS] --song <song> --song-volume <volume>
|
2021-06-12 03:20:56 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-06-12 03:20:56 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
|
|
|
|
2021-10-14 17:16:20 +00:00
|
|
|
OVERRIDE SPECIAL:
|
|
|
|
-b, --song <song> Change which song is played for birthdays
|
|
|
|
|
2021-06-12 03:20:56 +00:00
|
|
|
SPECIAL:
|
2021-09-24 15:58:39 +00:00
|
|
|
-v, --song-volume <volume> Change the volume of the birthday song
|
|
|
|
";
|
2021-06-12 03:20:56 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-11-29 16:45:30 +00:00
|
|
|
fn custom_help_headers_hide_args() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("blorp")
|
2021-06-12 03:20:56 +00:00
|
|
|
.author("Will M.")
|
|
|
|
.about("does stuff")
|
|
|
|
.version("1.4")
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(Some("NETWORKING"))
|
2021-06-12 03:20:56 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("no-proxy")
|
|
|
|
.short('n')
|
|
|
|
.long("no-proxy")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Do not use system proxy settings")
|
2021-11-29 16:45:30 +00:00
|
|
|
.hide_short_help(true),
|
2021-06-12 03:20:56 +00:00
|
|
|
)
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(Some("SPECIAL"))
|
2021-06-12 03:20:56 +00:00
|
|
|
.arg(
|
2021-11-19 20:33:11 +00:00
|
|
|
arg!(-b --song <song> "Change which song is played for birthdays")
|
2021-10-14 17:16:20 +00:00
|
|
|
.help_heading(Some("OVERRIDE SPECIAL")),
|
2021-06-12 03:20:56 +00:00
|
|
|
)
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(arg!(
|
|
|
|
-v --"song-volume" <volume> "Change the volume of the birthday song"
|
2021-10-14 17:16:20 +00:00
|
|
|
))
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(None)
|
2021-06-12 03:20:56 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("server-addr")
|
|
|
|
.short('a')
|
|
|
|
.long("server-addr")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Set server address")
|
2021-06-12 03:20:56 +00:00
|
|
|
.help_heading(Some("NETWORKING"))
|
2021-11-29 16:45:30 +00:00
|
|
|
.hide_short_help(true),
|
2021-06-12 03:20:56 +00:00
|
|
|
);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test -h", CUSTOM_HELP_SECTION_HIDDEN_ARGS, false);
|
2021-06-12 03:20:56 +00:00
|
|
|
}
|
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static ISSUE_897: &str = "ctest-foo 0.1
|
2018-06-12 14:01:42 +00:00
|
|
|
Long about foo
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest foo
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2020-08-20 12:45:38 +00:00
|
|
|
-h, --help
|
2021-07-30 03:23:25 +00:00
|
|
|
Print help information
|
2018-06-12 14:01:42 +00:00
|
|
|
|
2020-08-20 12:45:38 +00:00
|
|
|
-V, --version
|
2021-09-24 15:58:39 +00:00
|
|
|
Print version information
|
|
|
|
";
|
2018-06-12 14:01:42 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_long_about_issue_897() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("foo")
|
2018-06-12 14:01:42 +00:00
|
|
|
.version("0.1")
|
|
|
|
.about("About foo")
|
2018-07-23 19:09:42 +00:00
|
|
|
.long_about("Long about foo"),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest foo --help", ISSUE_897, false);
|
2018-06-12 14:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-02 13:27:19 +00:00
|
|
|
static ISSUE_897_SHORT: &str = "ctest-foo 0.1
|
2020-02-13 00:31:45 +00:00
|
|
|
About foo
|
2018-06-12 14:01:42 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest foo
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2018-06-12 14:01:42 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_short_about_issue_897() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("foo")
|
2018-06-12 14:01:42 +00:00
|
|
|
.version("0.1")
|
|
|
|
.about("About foo")
|
2018-07-23 19:09:42 +00:00
|
|
|
.long_about("Long about foo"),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest foo -h", ISSUE_897_SHORT, false);
|
2018-06-12 14:01:42 +00:00
|
|
|
}
|
2019-06-25 23:02:53 +00:00
|
|
|
|
2020-04-16 15:21:41 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_1364_no_short_options() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("demo")
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("foo").short('f'))
|
2020-04-16 15:21:41 +00:00
|
|
|
.arg(
|
2020-05-14 20:50:56 +00:00
|
|
|
Arg::new("baz")
|
2020-04-16 15:21:41 +00:00
|
|
|
.short('z')
|
|
|
|
.value_name("BAZ")
|
2021-11-29 16:45:30 +00:00
|
|
|
.hide_short_help(true),
|
2020-04-16 15:21:41 +00:00
|
|
|
)
|
2021-02-24 15:07:57 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("files")
|
|
|
|
.value_name("FILES")
|
|
|
|
.takes_value(true)
|
2021-06-16 05:28:25 +00:00
|
|
|
.multiple_values(true),
|
2021-02-24 15:07:57 +00:00
|
|
|
);
|
2020-04-16 15:21:41 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "demo -h", ISSUE_1364, false);
|
2020-04-16 15:21:41 +00:00
|
|
|
}
|
|
|
|
|
2020-01-11 18:15:46 +00:00
|
|
|
#[rustfmt::skip]
|
2019-06-25 23:02:53 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_1487() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("arg1")
|
2019-06-25 23:02:53 +00:00
|
|
|
.group("group1"))
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("arg2")
|
2019-06-25 23:02:53 +00:00
|
|
|
.group("group1"))
|
2020-05-14 20:50:56 +00:00
|
|
|
.group(ArgGroup::new("group1")
|
2019-06-25 23:02:53 +00:00
|
|
|
.args(&["arg1", "arg2"])
|
|
|
|
.required(true));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest -h", ISSUE_1487, false);
|
2020-01-11 18:15:46 +00:00
|
|
|
}
|
2020-02-10 10:04:18 +00:00
|
|
|
|
2020-04-09 16:19:05 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2020-02-10 10:04:18 +00:00
|
|
|
#[test]
|
2022-02-12 03:48:29 +00:00
|
|
|
#[should_panic = "AppSettings::HelpExpected is enabled for the Command"]
|
2020-02-10 10:04:18 +00:00
|
|
|
fn help_required_but_not_given() {
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("myapp")
|
2022-02-10 17:51:40 +00:00
|
|
|
.help_expected(true)
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("foo"))
|
2021-12-27 18:56:12 +00:00
|
|
|
.try_get_matches_from(empty_args())
|
|
|
|
.unwrap();
|
2020-02-10 10:04:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 16:19:05 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2020-02-10 10:04:18 +00:00
|
|
|
#[test]
|
2022-02-12 03:48:29 +00:00
|
|
|
#[should_panic = "AppSettings::HelpExpected is enabled for the Command"]
|
2020-02-10 10:04:18 +00:00
|
|
|
fn help_required_but_not_given_settings_after_args() {
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("myapp")
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("foo"))
|
2022-02-10 17:51:40 +00:00
|
|
|
.help_expected(true)
|
2021-12-27 18:56:12 +00:00
|
|
|
.try_get_matches_from(empty_args())
|
|
|
|
.unwrap();
|
2020-02-10 10:04:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 16:19:05 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2020-02-10 10:04:18 +00:00
|
|
|
#[test]
|
2022-02-12 03:48:29 +00:00
|
|
|
#[should_panic = "AppSettings::HelpExpected is enabled for the Command"]
|
2020-02-10 10:04:18 +00:00
|
|
|
fn help_required_but_not_given_for_one_of_two_arguments() {
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("myapp")
|
2022-02-10 17:51:40 +00:00
|
|
|
.help_expected(true)
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("foo"))
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("bar").help("It does bar stuff"))
|
2021-12-27 18:56:12 +00:00
|
|
|
.try_get_matches_from(empty_args())
|
|
|
|
.unwrap();
|
2020-02-10 10:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-02-10 17:51:40 +00:00
|
|
|
#[should_panic = "List of such arguments: delete"]
|
|
|
|
fn help_required_globally() {
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("myapp")
|
2022-02-10 17:51:40 +00:00
|
|
|
.help_expected(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("foo").help("It does foo stuff"))
|
2020-02-10 13:33:26 +00:00
|
|
|
.subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("bar")
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("create").help("creates bar"))
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("delete")),
|
2020-02-10 13:33:26 +00:00
|
|
|
)
|
2021-12-27 18:56:12 +00:00
|
|
|
.try_get_matches_from(empty_args())
|
|
|
|
.unwrap();
|
2020-02-10 13:33:26 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 16:19:05 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2020-02-10 13:33:26 +00:00
|
|
|
#[test]
|
2022-02-12 03:48:29 +00:00
|
|
|
#[should_panic = "AppSettings::HelpExpected is enabled for the Command"]
|
2020-02-10 13:33:26 +00:00
|
|
|
fn help_required_globally_but_not_given_for_subcommand() {
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("myapp")
|
2022-02-10 17:51:40 +00:00
|
|
|
.help_expected(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("foo").help("It does foo stuff"))
|
2020-02-10 10:04:18 +00:00
|
|
|
.subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("bar")
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("create").help("creates bar"))
|
2020-05-14 20:50:56 +00:00
|
|
|
.arg(Arg::new("delete")),
|
2020-02-10 10:04:18 +00:00
|
|
|
)
|
2021-12-27 18:56:12 +00:00
|
|
|
.try_get_matches_from(empty_args())
|
|
|
|
.unwrap();
|
2020-02-10 10:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_required_and_given_for_subcommand() {
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("myapp")
|
2022-02-10 17:51:40 +00:00
|
|
|
.help_expected(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("foo").help("It does foo stuff"))
|
2020-02-10 10:04:18 +00:00
|
|
|
.subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("bar")
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("create").help("creates bar"))
|
|
|
|
.arg(Arg::new("delete").help("deletes bar")),
|
2020-02-10 10:04:18 +00:00
|
|
|
)
|
2021-12-27 18:56:12 +00:00
|
|
|
.try_get_matches_from(empty_args())
|
|
|
|
.unwrap();
|
2020-02-10 10:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_required_and_given() {
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("myapp")
|
2022-02-10 17:51:40 +00:00
|
|
|
.help_expected(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("foo").help("It does foo stuff"))
|
2021-12-27 18:56:12 +00:00
|
|
|
.try_get_matches_from(empty_args())
|
|
|
|
.unwrap();
|
2020-02-10 10:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_required_and_no_args() {
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("myapp")
|
2022-02-10 17:51:40 +00:00
|
|
|
.help_expected(true)
|
2021-12-27 18:56:12 +00:00
|
|
|
.try_get_matches_from(empty_args())
|
|
|
|
.unwrap();
|
2020-02-10 10:04:18 +00:00
|
|
|
}
|
2020-08-11 21:46:09 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_1642_long_help_spacing() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("prog").arg(Arg::new("cfg").long("config").long_help(
|
2020-08-11 21:46:09 +00:00
|
|
|
"The config file used by the myprog must be in JSON format
|
|
|
|
with only valid keys and may not contain other nonsense
|
|
|
|
that cannot be read by this program. Obviously I'm going on
|
|
|
|
and on, so I'll stop now.",
|
|
|
|
));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "prog --help", ISSUE_1642, false);
|
2020-08-11 21:46:09 +00:00
|
|
|
}
|
2020-08-14 20:11:12 +00:00
|
|
|
|
|
|
|
const AFTER_HELP_NO_ARGS: &str = "myapp 1.0
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
myapp
|
|
|
|
|
|
|
|
This is after help.
|
|
|
|
";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn after_help_no_args() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let mut cmd = Command::new("myapp")
|
2020-08-14 20:11:12 +00:00
|
|
|
.version("1.0")
|
2022-02-10 17:51:40 +00:00
|
|
|
.disable_help_flag(true)
|
|
|
|
.disable_version_flag(true)
|
2020-08-14 20:11:12 +00:00
|
|
|
.after_help("This is after help.");
|
|
|
|
|
|
|
|
let help = {
|
|
|
|
let mut output = Vec::new();
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd.write_help(&mut output).unwrap();
|
2020-08-14 20:11:12 +00:00
|
|
|
String::from_utf8(output).unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(help, AFTER_HELP_NO_ARGS);
|
|
|
|
}
|
2020-09-24 21:49:12 +00:00
|
|
|
|
2021-10-15 18:27:40 +00:00
|
|
|
static HELP_SUBCMD_HELP: &str = "myapp-help
|
|
|
|
Print this message or the help of the given subcommand(s)
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
myapp help [SUBCOMMAND]...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<SUBCOMMAND>... The subcommand whose help message to display
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-11-18 16:17:15 +00:00
|
|
|
-h, --help Print custom help text
|
2021-10-15 18:27:40 +00:00
|
|
|
";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_subcmd_help() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("myapp")
|
2021-11-18 16:17:15 +00:00
|
|
|
.mut_arg("help", |h| h.help("Print custom help text"))
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("subcmd").subcommand(Command::new("multi").version("1.0")));
|
2021-10-15 18:27:40 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd.clone(), "myapp help help", HELP_SUBCMD_HELP, false);
|
2021-10-15 18:27:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static SUBCMD_HELP_SUBCMD_HELP: &str = "myapp-subcmd-help
|
|
|
|
Print this message or the help of the given subcommand(s)
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
myapp subcmd help [SUBCOMMAND]...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<SUBCOMMAND>... The subcommand whose help message to display
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-11-18 16:17:15 +00:00
|
|
|
-h, --help Print custom help text
|
2021-10-15 18:27:40 +00:00
|
|
|
";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn subcmd_help_subcmd_help() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("myapp")
|
2021-11-18 16:17:15 +00:00
|
|
|
.mut_arg("help", |h| h.help("Print custom help text"))
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("subcmd").subcommand(Command::new("multi").version("1.0")));
|
2021-10-15 18:27:40 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd.clone(),
|
2021-10-15 18:27:40 +00:00
|
|
|
"myapp subcmd help help",
|
|
|
|
SUBCMD_HELP_SUBCMD_HELP,
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-10-15 18:27:40 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 21:49:12 +00:00
|
|
|
static HELP_ABOUT_MULTI_SC: &str = "myapp-subcmd-multi 1.0
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
myapp subcmd multi
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-11-18 16:17:15 +00:00
|
|
|
-h, --help Print custom help text
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2020-09-24 21:49:12 +00:00
|
|
|
|
|
|
|
static HELP_ABOUT_MULTI_SC_OVERRIDE: &str = "myapp-subcmd-multi 1.0
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
myapp subcmd multi
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-11-18 16:17:15 +00:00
|
|
|
-h, --help Print custom help text from multi
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2020-09-24 21:49:12 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_about_multi_subcmd() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("myapp")
|
2021-11-18 16:17:15 +00:00
|
|
|
.mut_arg("help", |h| h.help("Print custom help text"))
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("subcmd").subcommand(Command::new("multi").version("1.0")));
|
2020-09-24 21:49:12 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd.clone(),
|
2020-09-24 21:49:12 +00:00
|
|
|
"myapp help subcmd multi",
|
|
|
|
HELP_ABOUT_MULTI_SC,
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd.clone(),
|
2020-09-24 21:49:12 +00:00
|
|
|
"myapp subcmd multi -h",
|
|
|
|
HELP_ABOUT_MULTI_SC,
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
utils::assert_output(cmd, "myapp subcmd multi --help", HELP_ABOUT_MULTI_SC, false);
|
2020-09-24 21:49:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_about_multi_subcmd_override() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("myapp")
|
2021-11-18 16:17:15 +00:00
|
|
|
.mut_arg("help", |h| h.help("Print custom help text"))
|
|
|
|
.subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("subcmd").subcommand(
|
|
|
|
Command::new("multi")
|
2021-11-18 16:17:15 +00:00
|
|
|
.version("1.0")
|
|
|
|
.mut_arg("help", |h| h.help("Print custom help text from multi")),
|
|
|
|
),
|
|
|
|
);
|
2020-09-24 21:49:12 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd.clone(),
|
2020-09-24 21:49:12 +00:00
|
|
|
"myapp help subcmd multi",
|
|
|
|
HELP_ABOUT_MULTI_SC_OVERRIDE,
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd.clone(),
|
2020-09-24 21:49:12 +00:00
|
|
|
"myapp subcmd multi -h",
|
|
|
|
HELP_ABOUT_MULTI_SC_OVERRIDE,
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2020-09-24 21:49:12 +00:00
|
|
|
"myapp subcmd multi --help",
|
|
|
|
HELP_ABOUT_MULTI_SC_OVERRIDE,
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2020-09-24 21:49:12 +00:00
|
|
|
}
|
2020-09-25 13:06:10 +00:00
|
|
|
|
2020-10-10 15:11:42 +00:00
|
|
|
#[test]
|
|
|
|
fn option_usage_order() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("order").args(&[
|
2020-10-10 15:11:42 +00:00
|
|
|
Arg::new("a").short('a'),
|
|
|
|
Arg::new("B").short('B'),
|
|
|
|
Arg::new("b").short('b'),
|
|
|
|
Arg::new("save").short('s'),
|
|
|
|
Arg::new("select_file").long("select_file"),
|
|
|
|
Arg::new("select_folder").long("select_folder"),
|
|
|
|
Arg::new("x").short('x'),
|
|
|
|
]);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "order --help", OPTION_USAGE_ORDER, false);
|
2020-10-10 15:11:42 +00:00
|
|
|
}
|
2020-12-08 17:04:21 +00:00
|
|
|
|
2021-06-20 15:28:50 +00:00
|
|
|
#[test]
|
2021-12-17 15:24:53 +00:00
|
|
|
fn prefer_about_over_long_about_in_subcommands_list() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("about-in-subcommands-list").subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("sub")
|
2021-10-12 00:21:06 +00:00
|
|
|
.long_about("long about sub")
|
|
|
|
.about("short about sub"),
|
|
|
|
);
|
2021-06-20 15:28:50 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-06-20 15:28:50 +00:00
|
|
|
"about-in-subcommands-list --help",
|
|
|
|
ABOUT_IN_SUBCOMMANDS_LIST,
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-06-20 15:28:50 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 17:04:21 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_1794_usage() {
|
2021-08-02 21:05:21 +00:00
|
|
|
static USAGE_WITH_GROUP: &str = "hello
|
2020-12-08 17:04:21 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
deno <pos1|--option1> [pos2]
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<pos1>
|
|
|
|
<pos2>
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-07-30 03:23:25 +00:00
|
|
|
-h, --help Print help information
|
2020-12-08 17:04:21 +00:00
|
|
|
--option1
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2020-12-08 17:04:21 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = clap::Command::new("hello")
|
2020-12-08 17:04:21 +00:00
|
|
|
.bin_name("deno")
|
|
|
|
.arg(Arg::new("option1").long("option1").takes_value(false))
|
|
|
|
.arg(Arg::new("pos1").takes_value(true))
|
|
|
|
.group(
|
|
|
|
ArgGroup::new("arg1")
|
|
|
|
.args(&["pos1", "option1"])
|
|
|
|
.required(true),
|
|
|
|
)
|
|
|
|
.arg(Arg::new("pos2").takes_value(true));
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "deno --help", USAGE_WITH_GROUP, false);
|
2020-12-08 17:04:21 +00:00
|
|
|
}
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2021-08-02 21:05:21 +00:00
|
|
|
static CUSTOM_HEADING_POS: &str = "test 1.4
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test [ARGS]
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<gear> Which gear
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-10-08 17:05:40 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
NETWORKING:
|
2021-09-24 15:58:39 +00:00
|
|
|
<speed> How fast
|
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn custom_heading_pos() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2021-02-08 03:33:57 +00:00
|
|
|
.version("1.4")
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("gear").help("Which gear"))
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(Some("NETWORKING"))
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("speed").help("How fast"));
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", CUSTOM_HEADING_POS, false);
|
2021-02-08 03:33:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 21:05:21 +00:00
|
|
|
static ONLY_CUSTOM_HEADING_OPTS_NO_ARGS: &str = "test 1.4
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
USAGE:
|
2021-10-12 00:13:51 +00:00
|
|
|
test [OPTIONS]
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
NETWORKING:
|
2021-09-24 15:58:39 +00:00
|
|
|
-s, --speed <SPEED> How fast
|
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn only_custom_heading_opts_no_args() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2021-02-08 03:33:57 +00:00
|
|
|
.version("1.4")
|
2022-02-10 17:51:40 +00:00
|
|
|
.disable_version_flag(true)
|
2021-11-29 16:45:30 +00:00
|
|
|
.mut_arg("help", |a| a.hide(true))
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(Some("NETWORKING"))
|
2021-11-19 20:33:11 +00:00
|
|
|
.arg(arg!(-s --speed <SPEED> "How fast").required(false));
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", ONLY_CUSTOM_HEADING_OPTS_NO_ARGS, false);
|
2021-02-08 03:33:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-02 21:05:21 +00:00
|
|
|
static ONLY_CUSTOM_HEADING_POS_NO_ARGS: &str = "test 1.4
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test [speed]
|
|
|
|
|
|
|
|
NETWORKING:
|
2021-09-24 15:58:39 +00:00
|
|
|
<speed> How fast
|
|
|
|
";
|
2021-02-08 03:33:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn only_custom_heading_pos_no_args() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2021-02-08 03:33:57 +00:00
|
|
|
.version("1.4")
|
2022-02-10 17:51:40 +00:00
|
|
|
.disable_version_flag(true)
|
2021-11-29 16:45:30 +00:00
|
|
|
.mut_arg("help", |a| a.hide(true))
|
2022-02-07 21:15:40 +00:00
|
|
|
.next_help_heading(Some("NETWORKING"))
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("speed").help("How fast"));
|
2021-02-08 03:33:57 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "test --help", ONLY_CUSTOM_HEADING_POS_NO_ARGS, false);
|
2021-02-08 03:33:57 +00:00
|
|
|
}
|
2021-07-20 19:38:58 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_2508_number_of_values_with_single_value_name() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("my_app")
|
2021-07-20 19:38:58 +00:00
|
|
|
.arg(Arg::new("some_arg").long("some_arg").number_of_values(2))
|
|
|
|
.arg(
|
|
|
|
Arg::new("some_arg_issue")
|
|
|
|
.long("some_arg_issue")
|
|
|
|
.number_of_values(2)
|
|
|
|
.value_name("ARG"),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-07-20 19:38:58 +00:00
|
|
|
"my_app --help",
|
|
|
|
"my_app
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
my_app [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
2021-07-20 19:38:58 +00:00
|
|
|
--some_arg <some_arg> <some_arg>
|
2021-09-24 15:58:39 +00:00
|
|
|
--some_arg_issue <ARG> <ARG>
|
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-07-20 19:38:58 +00:00
|
|
|
}
|
2021-07-31 06:39:23 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn missing_positional_final_required() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2022-02-10 17:51:40 +00:00
|
|
|
.allow_missing_positional(true)
|
2021-07-31 06:39:23 +00:00
|
|
|
.arg(Arg::new("arg1"))
|
|
|
|
.arg(Arg::new("arg2").required(true));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-07-31 06:39:23 +00:00
|
|
|
"test --help",
|
|
|
|
"test
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test [arg1] <arg2>
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<arg1>
|
|
|
|
<arg2>
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-10-08 17:05:40 +00:00
|
|
|
-h, --help Print help information
|
2021-07-31 06:39:23 +00:00
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-07-31 06:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn missing_positional_final_multiple() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test")
|
2022-02-10 17:51:40 +00:00
|
|
|
.allow_missing_positional(true)
|
2021-07-31 06:39:23 +00:00
|
|
|
.arg(Arg::new("foo"))
|
|
|
|
.arg(Arg::new("bar"))
|
|
|
|
.arg(Arg::new("baz").takes_value(true).multiple_values(true));
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-07-31 06:39:23 +00:00
|
|
|
"test --help",
|
|
|
|
"test
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test [ARGS]
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<foo>
|
|
|
|
<bar>
|
|
|
|
<baz>...
|
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-10-08 17:05:40 +00:00
|
|
|
-h, --help Print help information
|
2021-07-31 06:39:23 +00:00
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-07-31 06:39:23 +00:00
|
|
|
}
|
2021-09-04 20:10:24 +00:00
|
|
|
|
2021-10-30 18:42:01 +00:00
|
|
|
#[test]
|
|
|
|
fn positional_multiple_values_is_dotted() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test").arg(
|
2021-10-30 18:42:01 +00:00
|
|
|
Arg::new("foo")
|
|
|
|
.required(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple_values(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-10-30 18:42:01 +00:00
|
|
|
"test --help",
|
|
|
|
"test
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test <foo>...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<foo>...
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h, --help Print help information
|
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-10-30 18:42:01 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test").arg(
|
2021-10-30 18:42:01 +00:00
|
|
|
Arg::new("foo")
|
|
|
|
.required(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("BAR")
|
|
|
|
.multiple_values(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-10-30 18:42:01 +00:00
|
|
|
"test --help",
|
|
|
|
"test
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test <BAR>...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<BAR>...
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h, --help Print help information
|
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-10-30 18:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn positional_multiple_occurrences_is_dotted() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test").arg(
|
2021-10-30 18:42:01 +00:00
|
|
|
Arg::new("foo")
|
|
|
|
.required(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.multiple_occurrences(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-10-30 18:42:01 +00:00
|
|
|
"test --help",
|
|
|
|
"test
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test <foo>...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<foo>...
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h, --help Print help information
|
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-10-30 18:42:01 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test").arg(
|
2021-10-30 18:42:01 +00:00
|
|
|
Arg::new("foo")
|
|
|
|
.required(true)
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("BAR")
|
|
|
|
.multiple_occurrences(true),
|
|
|
|
);
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-10-30 18:42:01 +00:00
|
|
|
"test --help",
|
|
|
|
"test
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
test <BAR>...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<BAR>...
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h, --help Print help information
|
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-10-30 18:42:01 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 20:10:24 +00:00
|
|
|
#[test]
|
|
|
|
fn disabled_help_flag() {
|
2022-02-12 03:48:29 +00:00
|
|
|
let res = Command::new("foo")
|
|
|
|
.subcommand(Command::new("sub"))
|
2022-02-10 17:51:40 +00:00
|
|
|
.disable_help_flag(true)
|
2021-11-17 20:23:22 +00:00
|
|
|
.try_get_matches_from("foo a".split(' '));
|
2021-10-08 17:05:40 +00:00
|
|
|
assert!(res.is_err());
|
|
|
|
let err = res.unwrap_err();
|
2022-01-25 22:19:28 +00:00
|
|
|
assert_eq!(err.kind(), ErrorKind::UnrecognizedSubcommand);
|
2021-09-04 20:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn disabled_help_flag_and_subcommand() {
|
2022-02-12 03:48:29 +00:00
|
|
|
let res = Command::new("foo")
|
|
|
|
.subcommand(Command::new("sub"))
|
2022-02-10 17:51:40 +00:00
|
|
|
.disable_help_flag(true)
|
|
|
|
.disable_help_subcommand(true)
|
2021-11-17 20:23:22 +00:00
|
|
|
.try_get_matches_from("foo help".split(' '));
|
2021-10-08 17:05:40 +00:00
|
|
|
assert!(res.is_err());
|
|
|
|
let err = res.unwrap_err();
|
2022-01-25 22:19:28 +00:00
|
|
|
assert_eq!(err.kind(), ErrorKind::UnrecognizedSubcommand);
|
2021-12-13 19:09:46 +00:00
|
|
|
assert!(
|
|
|
|
err.to_string().ends_with('\n'),
|
|
|
|
"Errors should have a trailing newline, got {:?}",
|
|
|
|
err.to_string()
|
|
|
|
);
|
2021-09-04 20:10:24 +00:00
|
|
|
}
|
2021-10-04 14:01:09 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn override_help_subcommand() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("bar")
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("help").arg(Arg::new("arg").takes_value(true)))
|
|
|
|
.subcommand(Command::new("not_help").arg(Arg::new("arg").takes_value(true)))
|
2022-02-10 17:51:40 +00:00
|
|
|
.disable_help_subcommand(true);
|
2022-02-14 21:47:20 +00:00
|
|
|
let matches = cmd.try_get_matches_from(&["bar", "help", "foo"]).unwrap();
|
2021-10-04 14:01:09 +00:00
|
|
|
assert_eq!(
|
|
|
|
matches.subcommand_matches("help").unwrap().value_of("arg"),
|
|
|
|
Some("foo")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn override_help_flag_using_long() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("foo")
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("help").long_flag("help"))
|
2022-02-10 17:51:40 +00:00
|
|
|
.disable_help_flag(true);
|
2022-02-14 21:47:20 +00:00
|
|
|
let matches = cmd.try_get_matches_from(&["foo", "--help"]).unwrap();
|
2021-10-04 14:01:09 +00:00
|
|
|
assert!(matches.subcommand_matches("help").is_some());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn override_help_flag_using_short() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("foo")
|
2022-02-10 17:51:40 +00:00
|
|
|
.disable_help_flag(true)
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("help").short_flag('h'));
|
2022-02-14 21:47:20 +00:00
|
|
|
let matches = cmd.try_get_matches_from(&["foo", "-h"]).unwrap();
|
2021-10-04 14:01:09 +00:00
|
|
|
assert!(matches.subcommand_matches("help").is_some());
|
|
|
|
}
|
2021-12-13 21:59:12 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn subcommand_help_doesnt_have_useless_help_flag() {
|
|
|
|
// The main care-about is that the docs and behavior match. Since the `help` subcommand
|
|
|
|
// currently ignores the `--help` flag, the output shouldn't have it.
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("test_app").subcommand(Command::new("test").about("Subcommand"));
|
2021-12-13 21:59:12 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd,
|
2021-12-13 21:59:12 +00:00
|
|
|
"example help help",
|
|
|
|
"example-help
|
|
|
|
Print this message or the help of the given subcommand(s)
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
example help [SUBCOMMAND]...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<SUBCOMMAND>... The subcommand whose help message to display
|
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2021-12-13 21:59:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn disable_help_flag_affects_help_subcommand() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let mut cmd = Command::new("test_app")
|
2022-02-10 17:51:40 +00:00
|
|
|
.disable_help_flag(true)
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(Command::new("test").about("Subcommand"));
|
2022-04-19 15:11:27 +00:00
|
|
|
cmd.build();
|
2021-12-13 21:59:12 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let args = cmd
|
2021-12-13 21:59:12 +00:00
|
|
|
.find_subcommand("help")
|
|
|
|
.unwrap()
|
|
|
|
.get_arguments()
|
2022-02-11 20:10:29 +00:00
|
|
|
.map(|a| a.get_id())
|
2021-12-13 21:59:12 +00:00
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert!(
|
|
|
|
!args.contains(&"help"),
|
|
|
|
"`help` should not be present: {:?}",
|
|
|
|
args
|
|
|
|
);
|
|
|
|
}
|
2022-01-18 20:36:48 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dont_propagate_version_to_help_subcommand() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = clap::Command::new("test")
|
2022-01-18 20:36:48 +00:00
|
|
|
.version("1.0")
|
2022-02-10 17:51:40 +00:00
|
|
|
.propagate_version(true)
|
2022-02-12 03:48:29 +00:00
|
|
|
.subcommand(clap::Command::new("subcommand"));
|
2022-01-18 20:36:48 +00:00
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd.clone(),
|
2022-01-18 20:36:48 +00:00
|
|
|
"example help help",
|
|
|
|
"example-help
|
|
|
|
Print this message or the help of the given subcommand(s)
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
example help [SUBCOMMAND]...
|
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<SUBCOMMAND>... The subcommand whose help message to display
|
|
|
|
",
|
2022-04-29 20:32:25 +00:00
|
|
|
false,
|
|
|
|
);
|
2022-01-18 20:36:48 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd.debug_assert();
|
2022-01-18 20:36:48 +00:00
|
|
|
}
|
2022-02-09 00:51:44 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_without_short() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let mut cmd = clap::Command::new("test")
|
2022-02-09 00:51:44 +00:00
|
|
|
.arg(arg!(-h --hex <NUM>))
|
|
|
|
.arg(arg!(--help));
|
|
|
|
|
2022-04-19 15:11:27 +00:00
|
|
|
cmd.build();
|
2022-02-14 21:47:20 +00:00
|
|
|
let help = cmd.get_arguments().find(|a| a.get_id() == "help").unwrap();
|
2022-02-09 00:51:44 +00:00
|
|
|
assert_eq!(help.get_short(), None);
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let m = cmd.try_get_matches_from(["test", "-h", "0x100"]).unwrap();
|
2022-02-09 00:51:44 +00:00
|
|
|
assert_eq!(m.value_of("hex"), Some("0x100"));
|
|
|
|
}
|
2022-04-29 20:39:17 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parent_cmd_req_in_usage_with_help_flag() {
|
|
|
|
static EXPECTED: &str = "parent-test
|
|
|
|
some
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
parent <TARGET> <ARGS> test
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h, --help Print help information
|
|
|
|
";
|
|
|
|
let cmd = Command::new("parent")
|
|
|
|
.version("0.1")
|
|
|
|
.arg(Arg::new("TARGET").required(true).help("some"))
|
|
|
|
.arg(
|
|
|
|
Arg::new("ARGS")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("some"),
|
|
|
|
)
|
|
|
|
.subcommand(Command::new("test").about("some"));
|
|
|
|
utils::assert_output(cmd, "parent test --help", EXPECTED, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parent_cmd_req_in_usage_with_help_subcommand() {
|
|
|
|
static EXPECTED: &str = "parent-test
|
|
|
|
some
|
|
|
|
|
|
|
|
USAGE:
|
2022-04-30 01:15:44 +00:00
|
|
|
parent <TARGET> <ARGS> test
|
2022-04-29 20:39:17 +00:00
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h, --help Print help information
|
|
|
|
";
|
|
|
|
let cmd = Command::new("parent")
|
|
|
|
.version("0.1")
|
|
|
|
.arg(Arg::new("TARGET").required(true).help("some"))
|
|
|
|
.arg(
|
|
|
|
Arg::new("ARGS")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("some"),
|
|
|
|
)
|
|
|
|
.subcommand(Command::new("test").about("some"));
|
|
|
|
utils::assert_output(cmd, "parent help test", EXPECTED, false);
|
|
|
|
}
|
2022-04-29 21:41:00 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parent_cmd_req_in_usage_with_render_help() {
|
|
|
|
static EXPECTED: &str = "parent-test
|
|
|
|
some
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
parent <TARGET> <ARGS> test
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-h, --help Print help information
|
|
|
|
";
|
|
|
|
let mut cmd = Command::new("parent")
|
|
|
|
.version("0.1")
|
|
|
|
.arg(Arg::new("TARGET").required(true).help("some"))
|
|
|
|
.arg(
|
|
|
|
Arg::new("ARGS")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("some"),
|
|
|
|
)
|
|
|
|
.subcommand(Command::new("test").about("some"));
|
|
|
|
cmd.build();
|
|
|
|
let subcmd = cmd.find_subcommand_mut("test").unwrap();
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
subcmd.write_help(&mut buf).unwrap();
|
|
|
|
utils::assert_eq(EXPECTED, String::from_utf8(buf).unwrap());
|
|
|
|
}
|