Commit graph

269 commits

Author SHA1 Message Date
tormol
996fc38176 docs: fix tests that fail when the "suggestions" feature is disabled 2016-10-16 11:31:12 +02:00
tormol
5778871951 style: remove the .ok() in result.ok().expect("...")
clippy doesn't check doc-tests and `include!()`d files,
so there might bee more un-reported lint.
2016-10-05 23:16:22 +02:00
tormol
215677bfa7 style: remove #[allow("warning that apparently doesn't exist")]
I say "apparently" because it's listed on https://manishearth.github.io/rust-clippy/master/
and not as deprecated.
2016-10-05 23:15:53 +02:00
Hideyuki Tanaka
8cd120c230 Fix the behavior of require_delimiter 2016-10-04 18:40:03 -04:00
nabijaczleweli
7b7aa87ddf
tests(correctness): No longer use App::get_matches() in some places
Use App::get_matches_from(vec![""]) instead not to fail when flags are
passed to the test binary

Closes #676
2016-10-04 23:22:43 +02:00
Salim Afiune
905d3b9777 Fix linting errors from rustc 1.14.0
The new version of rustc 1.14.0-nightly (144af3e97 2016-10-02) has new
linting warnings/errors. This commit fixes them.

Signed-off-by: Salim Afiune <afiune@chef.io>
2016-10-04 12:26:51 -04:00
Salim Afiune
40d6dac973 feat(flag_aliases): Ability to alias flags
Added same alias funtionality for flags, now you can do:
```
Arg::with_name("flg")
    .long("flag")
    .short("f")
    .alias("not_visible_flag")
    .visible_alias("awesome_v_flag")
```

Signed-off-by: Salim Afiune <afiune@chef.io>
2016-10-04 12:26:51 -04:00
Salim Afiune
e5d9760bea Added Arg::(visible_)alias(es) docs
Signed-off-by: Salim Afiune <afiune@chef.io>
2016-10-04 12:26:51 -04:00
Salim Afiune
33b5f6ef2c feat(arg_aliases): Ability to alias arguments
There are some cases where you need to have an argument to have an
alias, an example could be when you depricate one option in favor of
another one.

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

Closes #669
2016-10-04 12:26:51 -04:00
Kevin K
d12649fd7b
tests: adds tests for value delimiters 2016-09-18 16:01:26 -04:00
Kevin K
5c29448d54
tests(AllowLeadingHyphen): adds test issue 588 AllowLeadingHyphen not recognizing valid args 2016-09-12 23:26:49 -04:00
Kevin K
1ea9bef20d
test(Help Wrapping): adds tests for the old newline characters 2016-09-12 23:20:40 -04:00
Kevin K
4c8ae08e4c
tests(Help): adds tests for per argument hiding of possible values 2016-09-10 23:11:43 -04:00
Kevin K
9881a4a23a tests(Value Delimiters): updates tests to new value delimiter rules 2016-09-10 18:18:43 -04:00
Kevin K
2e99e22630 Merge branch 'master' into issue-617 2016-09-07 10:45:27 -04:00
Kevin K
934094d7c5 tests: updates tests for new help wrapping rules 2016-09-07 08:42:42 -04:00
Aluísio Augusto Silva Gonçalves
b9b55a39df
imp(YAML): supports setting Arg::require_delimiter from YAML 2016-09-06 13:30:31 -03:00
Kevin K
60de29a7ef tests: updates test to new help improvements 2016-09-05 20:46:18 -04:00
Kevin K
3617a1d493 test: updates app_settings tests for new bug fixes 2016-09-05 17:16:40 -04:00
Kevin K
b7793a2f4d Issues rollup (#637)
* feat: adds App::with_defaults to automatically use crate_authors! and crate_version! macros

One can now use

```rust
let a = App::with_defaults("My Program");

// same as
let a2 = App::new("My Program")
	.version(crate_version!())
	.author(crate_authors!());
```

Closes #600

* imp(YAML Errors): vastly improves error messages when using YAML

When errors are made while developing, the panic error messages have
been improved instead of relying on the default panic message which is
extremely unhelpful.

Closes #574

* imp(Completions): uses standard conventions for bash completion files, namely '{bin}.bash-completion'

Closes #567

* imp(Help): automatically moves help text to the next line and wraps when term width is determined to be too small, or help text is too long

Now `clap` will check if it should automatically place long help
messages on the next line after the flag/option. This is determined by
checking to see if the space taken by flag/option plus spaces and values
doesn't leave enough room for the entirety of the help message, with the
single exception of of if the flag/option/spaces/values is less than 25%
of the width.

Closes #597

* tests: updates help tests to new forced new line rules

* fix(Groups): fixes some usage strings that contain both args in groups and ones that conflict with each other

Args that conflict *and* are in a group will now only display in the
group and not in the usage string itself.

Closes #616

* chore: updates dep graph

Closes #633

* chore: clippy run

* style: changes debug header to match other Rust projects

* chore: increase version
2016-08-27 23:42:31 -04:00
Kevin K
cdb9037c15 tests: updates tests to account for variable term widths and non-english chars 2016-08-25 18:50:48 -04:00
Kevin K
881a647ee9 tests: adds tests to prevent issue 626 2016-08-24 21:50:20 -04:00
Kevin K
7558261c88 tests: adds tests for ignoring term width with set_term_width(0) 2016-08-24 19:39:31 -04:00
Kevin K
9e8e350b95 tests: adds tests for multi level help subcommands 2016-08-20 17:17:58 -04:00
Kathryn Long
aebc8fd828 tests(template): fix template asserts on windows 2016-07-26 23:46:06 -05:00
Barret Rennie
0ceba231c6 feat(Settings): Add unset_setting and unset_settings fns to App (#598)
Closes #590.
2016-07-24 00:08:24 -04:00
Kevin K
625cbbca0d test: adds tests for required_unless_one cases 2016-07-23 17:22:14 -04:00
Christopher Field
1b99091e0a tests: adds require_unless_one test cases
* test: `require_unless_one` with second argument

Add the `require_unless_one_2` test. This tests that when the second
argument in the array is used at the command line, that the required
argument is not present. This test was added because it appears the
`require_unless_one` function only works for the first argument in the
array.

* Fix: assertions for test

The assertions did not check for the `infile` to be present.
2016-07-23 13:43:22 -04:00
David Szotten
9f62cf7378 feat(Completions): adds the ability to generate completions to io::Write object 2016-07-14 09:38:13 +01:00
Bence Szigeti
f8ca3085da Fix: typo -- missing space and commas 2016-07-05 22:14:47 +02:00
Bence Szigeti
8d7bea823f Fix: extra space typo removed 2016-07-05 22:01:04 +02:00
Kevin K
93cbb56f77 tests: adds tests for leading hyphen issues 2016-07-01 13:50:32 -04:00
Kevin K
98a7e8a636 tests(Arg): adds tests for
Closes #546
2016-06-29 23:01:47 -04:00
Kevin K
c84834abbb tests(Options): adds tests to cover new stop parsing vals after spaces with equals or delims 2016-06-29 13:30:30 -04:00
Kevin K
4f805d53e7 tests(Usage Strings): updates usage string tests 2016-06-24 00:17:04 -04:00
Kevin K
ba68caa3d1 tests(Groups): adds test for groups with multiple allowed 2016-06-23 12:42:41 -04:00
Kevin K
eb7521a996 tests(Aliases): adds tests for alias help output 2016-06-12 21:52:18 -04:00
Kevin K
2ff981b9be tests: adds tests for visible aliases 2016-06-09 22:50:02 -04:00
Kevin K
5354d14b51 fix(Subcommands): subcommands with aliases now display help of the aliased subcommand
Imagine subcommand `foo` had alias `bar`, running `myprog help bar` now correctly displays the help
for `foo`

Closes #521
2016-06-09 20:39:53 -04:00
Kevin K
785ff83a14 tests(Settings): adds tests for DontDelimitTrailingValues 2016-06-07 23:49:05 -04:00
Kevin K
6e7f3e0556 tests(Usage Strings): adds tests for single positional arg usage strings 2016-06-04 11:55:47 -04:00
Kevin K
17bc17c699 tests(Settings): adds tests for global subcommands 2016-06-04 11:55:47 -04:00
Kevin K
9582b82789 tests: adds test to check for before_help 2016-06-04 11:55:47 -04:00
Kevin K
c8cc87ac10 tests: updates help tests to remove extra newline 2016-06-04 11:55:47 -04:00
Kevin K
c5b24c0eb0 tests: removes extra newline from version output tests 2016-06-04 11:28:24 -04:00
Kevin K
fd8e211895 tests(Subcommand Aliases): adds tests for new aliases 2016-05-10 15:26:43 -04:00
Kevin K
b42ca0b5ab chore(Tests): had to remove external clap-test crate...sad face 2016-05-09 22:46:09 -04:00
Kevin K
417dbc3057 test: adds test for new group deduping 2016-05-09 19:14:11 -04:00
Kevin K
852e58156c tests: removes old python tests and replaces with rust tests
Closes #166
2016-05-09 19:14:11 -04:00
Kevin K
a0a56318d0 tests(Groups): adds tests for positional arg formatting in groups 2016-05-08 21:33:56 -04:00
Kevin K
250ed41f10 tests(Help): changes formatting for positional arguments 2016-05-08 20:38:13 -04:00
Kevin K
9fdad2e970 tests: adds tests for required_unless settings 2016-05-03 16:31:54 -04:00
Hernan Grecco
627ae38dc0 refactor(HELP): Removed code for old help system and tests that helped with the transitions 2016-04-13 07:21:21 -03:00
Hernan Grecco
81e121edd6 feat(HELP): Add a Templated Help system.
The strategy is to copy the template from the the reader to wrapped stream
until a tag is found. Depending on its value, the appropriate content is copied
to the wrapped stream.
The copy from template is then resumed, repeating this sequence until reading
the complete template.

Tags arg given inside curly brackets:
Valid tags are:
    * `{bin}`         - Binary name.
    * `{version}`     - Version number.
    * `{author}`      - Author information.
    * `{usage}`       - Automatically generated or given usage string.
    * `{all-args}`    - Help for all arguments (options, flags, positionals arguments,
                        and subcommands) including titles.
    * `{unified}`     - Unified help for options and flags.
    * `{flags}`       - Help for flags.
    * `{options}`     - Help for options.
    * `{positionals}` - Help for positionals arguments.
    * `{subcommands}` - Help for subcommands.
    * `{after-help}`  - Help for flags.
2016-04-13 07:06:23 -03:00
Hernan Grecco
04b5b074d1 refactor(HELP): A new Help Engine
The largest organizational change is that methods used to generate the help are
implemented by the Help object and not the App, FlagBuilder, Parser, etc.

The new code is based heavily on the old one with a few minor modifications
aimed to reduce code duplication and coupling between the Help and the rest
of the code.

The new code turn things around: instead of having a HelpWriter that holds an
AnyArg object and a method that is called with a writer as argument,
there is a Help Object that holds a writer and a method that is called with a
writer as an argument.

There are still things to do such as moving `create_usage` outside the Parser.

The peformance has been affected, probably by the use of Trait Objects. This
was done as a way to reduce code duplication (i.e. in the unified help code).
This performance hit should not affect the usability as generating and printing
the help is dominated by user interaction and IO.

The old code to generate the help is still functional and is the active one.
The new code has been tested against the old one by generating help strings
for most of the examples in the repo.
2016-04-13 07:06:23 -03:00
Kevin K
c3795ad404 tests(Groups): removes tests causing issues that werent required 2016-04-09 22:33:49 -07:00
Kevin K
0e69314e53 test(Help Message): adds test to prevent issue-472 2016-04-02 20:47:27 -04:00
Kevin K
baf0e18095 tests(Empty Values): adds tests for empty values 2016-03-29 22:31:40 -04:00
Kevin K
991aefc10a tests: updates tests to new verions 2016-03-16 10:22:00 -04:00
Kevin K
675c39f8ba tests: moves app settings tests to the proper place 2016-03-13 22:07:28 -04:00
Kevin K
e428bb6d84 tests: moves some \t tabs to four spaces for consistency 2016-03-13 22:07:28 -04:00
Kevin K
6efa298cba test: fixes failing doc tests 2016-02-19 01:47:37 -05:00
Kevin K
9250b1323c tests: adds tests for default values 2016-02-10 10:56:58 -05:00
Kevin K
26f2e5feb0 tests(Multiple Values): fixes failing benches and adds tests to guard 2016-02-04 22:15:10 -05:00
Kevin K
2ba12b8b76 tests(Multiple Values): adds test for exact number of values 2016-02-04 19:44:30 -05:00
Kevin K
4f207a1195 tests(AppSettings): adds test for GlobalVersion 2016-02-04 11:55:58 -05:00
Kevin K
a33e3df8f5 tests: adds tests for stdin char and only positional vals follow 2016-02-04 02:01:10 -05:00
Alex Hill
85b11468b0 fix: Stop lonely hyphens from causing panic
The method `starts_with` as implemented for the `OsStrExt2` trait on
`OsStr` assumed that the needle given is shorter than the haystack. When
this is not the case, the method panics due to an attempted
out-of-bounds access on the byte representation of `self`. Problematic
if, say, an end-user gives us `"-"` and the library tries to see if that
starts with `"--"`.

Fortunately, slices already implement a `starts_with` method, and we can
delegate to it.

This *does* create a semantics change: if both `self` and the needle
have length 0, this implementation will return `true`, but the old
implementation would return `false`. Based on the test suite still
passing, acknowledging the vacuous truth doesn't seem to cause any
problems.

Fixes #410
2016-02-02 21:05:45 -08:00
Kevin K
07dfdd00ea tests(multiples): adds tests for > u8::max vals and occurrences 2016-02-02 07:45:49 -05:00
Kevin K
7596951a30 tests: adds additional tests for new setting and missing old tests 2016-02-02 07:21:01 -05:00
Ceri Storey
3731ddb361 fix(matched_arg): Allow for more than 256 occurrences of an argument. 2016-02-02 19:30:32 +00:00
Kevin K
4735f4d5cb tests(SubCommands): adds tests for subcmds after mult args 2016-01-31 07:37:20 -05:00
Kevin K
816cec8152 tests(Usage Parser): moves tests usage parser since that's what it's testing 2016-01-31 07:12:15 -05:00
Kevin K
90542747ac chore: fixes doc and style mistakes 2016-01-28 21:58:40 -05:00
Kevin K
474f27af43 tests: adds tests for values when delims have been turned off 2016-01-28 11:45:31 -05:00
Kevin K
7b0ff38fe7 tests: adds tests for different value delimiters 2016-01-28 11:45:31 -05:00
Kevin K
28041cdad9 tests: adds tests for comma separated values 2016-01-28 11:45:31 -05:00
Kevin K
f17e150894 tests(Usage Parser): adds and fixes tests for usage parser 2016-01-28 11:45:31 -05:00
Kevin K
32dd302f97 tests: fixes tests for optional option values 2016-01-28 11:45:31 -05:00
Kevin K
e874a0d5e0 feat(UTF-8): adds support for invalid utf8 in values
Closes #269
2016-01-28 11:45:31 -05:00
Kevin K
c3e96232c9 tests(v2): fixing more tests on the new v2 base 2016-01-28 11:45:31 -05:00
Kevin K
0031d78564 refactor(v2): improving macros for code dedup 2016-01-28 11:45:31 -05:00
Kevin K
7fc18e685f test(v2): fixing tests to pass under new v2 changes 2016-01-28 11:45:31 -05:00
Sung Rim Huh
44cbed1a2a tests(help): add tests for help subcommand 2016-01-14 20:23:50 -08:00
Sung Rim Huh
32ef3264b9 tests: add checks for help and version flag 2016-01-13 09:03:27 -08:00
Sung Rim Huh
1c41d1bf43 tests(possible_values): add tests for possible values 2016-01-13 08:52:42 -08:00
Sung Rim Huh
e2c63cded7 tests(multiple_values): add positional multiple values 2016-01-13 08:28:24 -08:00
Sung Rim Huh
346450e6f1 tests(subcommands): add subcommand tests 2016-01-13 08:06:00 -08:00
Sung Rim Huh
3936b28035 tests(yaml): use scope wide attribute 2016-01-11 21:13:14 -08:00
Sung Rim Huh
b2d29b0a68 tests(unicode): use scope wide attribute 2016-01-11 21:08:38 -08:00
Kevin K
6372b4844f tests(unicode): removes unicode testing from Windows builds 2015-12-18 09:01:59 -05:00
Sung Rim Huh
389d14ab85 tests(multiple_values): move tests related to multiple values 2015-12-10 09:09:50 -08:00
Kevin K
8988853fb8 imp(ArgMatcher): huge refactor and deduplication of code
Tons of code has been moved into functions, deduplicated, made much
easier to read, maintain, and understand. Comments still need to be
added, but that will happen shortly. Modules have also been moved around
to follow Rust conventions and best practices.

All functionality remains exactly the same
2015-11-11 10:26:05 -05:00
Kevin K
ea4740ca3b tests(Errors): improves error testing 2015-11-03 08:26:17 -05:00
Kevin K
aff89d579b feat: allows parsing without a binary name for daemons and interactive CLIs
Closes #318
2015-10-28 06:45:49 -04:00
Kevin K
40ed2b50c3 fix(POSIX Overrides): fixes bug where required args are overridden 2015-10-28 04:51:42 -04:00
Kevin K
13f6101a87 tests(Unified Help): uses new sorted category in tests
Closes #307
2015-10-05 20:37:49 -04:00
Kevin K
1ac7e99491 tests(AppSettings): adds some additional tests 2015-09-30 23:59:41 -04:00
Kevin K
38ff779749 tests(Hidden Args): adds tests 2015-09-30 23:59:41 -04:00
Kevin K
7005cf8c47 style: removes trailing whitespace 2015-09-30 23:59:40 -04:00
Alexander Kuvaev
e102c1be3f tests: minor test improvements 2015-09-28 23:28:46 +03:00
Kevin K
af8bfb1610 tests(ArgGroups): adds tests for ArgGroups
closes #279
2015-09-28 12:29:57 -04:00
Kevin K
8b1b261616 tests(Unicode): adds safe unicode tests 2015-09-21 21:58:41 -04:00
Alexander Kuvaev
eb65a07a91 tests: some new tests for positionals 2015-09-17 22:20:56 +03:00
Kevin K
4a6ad4e73a tests(App Help): tests writing of App help message 2015-09-08 22:39:31 -04:00
Alexander Kuvaev
5ef59a7a19 tests: fixed yaml test 2015-09-06 23:34:15 +03:00
Alexander Kuvaev
7a2375bcea tests: add tests for requires 2015-09-06 23:13:55 +03:00
Alexander Kuvaev
7fdcb4761a tests: Added requirement override tests 2015-09-06 22:34:37 +03:00
Alexander Kuvaev
952fa4d246 tests: conflict override tests 2015-09-06 22:22:37 +03:00
Alexander Kuvaev
7e3e696471 tests: Add sub_command_negate_requred false-negative test 2015-09-06 22:13:16 +03:00
Alexander Kuvaev
a4a00b03e3 tests: add tests for flag and groups conflicts 2015-09-06 13:46:58 +03:00
Kevin K
e1694922f5 tests: adds test for ArgGroups 2015-09-04 13:58:00 -04:00
Kevin K
e27a3f3146 tests: adds tests for AppSettings FromStr 2015-09-04 13:16:24 -04:00
Kevin K
ab41d7f382 docs(YAML): adds examples for using YAML to build a CLI 2015-08-31 23:57:35 -04:00
Kevin K
1a3c729e7f test(App from YAML): fixes yaml app declaration 2015-08-31 23:57:35 -04:00
Kevin K
86cf4c4562 feat(YAML): allows building a CLI from YAML files 2015-08-31 23:57:16 -04:00
Alexander Kuvaev
0cfecd328c tests: moved tests from lib.rs to tests.rs and tests dir 2015-08-28 21:48:37 +03:00
Kevin K
c7f22728f1 Added test application 2015-03-24 12:16:59 -04:00
Kevin K
0f7bc363ce Moved tests to tests/ directory and crate 2015-03-22 21:57:02 -04:00