Commit graph

695 commits

Author SHA1 Message Date
Kevin K
054f8cb433 imp: removes extra newline from help output 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
a7401dc6a1 imp: allows printing version to any io::Write object 2016-06-04 11:28:24 -04:00
Kevin K
cda27469cd imp: removes extra newline when printing version 2016-06-04 11:28:24 -04:00
Kevin K
65c2350aa3 feat: colors dont get sent to pipes by default
Color are now only used when outputting to a termainal/TTY. There are three new settings as well
which can be used to control color output, they are:

 * `AppSettings::ColorAuto`: The default, and will only output color when outputting to a terminal or TTY
 * `AppSettings::ColorAlways`: Outputs color no matter where the output is going
 * `AppSettings::ColorNever`: Never colors output

This now allows one to use things like command line options, or environmental variables to turn
colored output on/off.

Closes #512
2016-06-04 11:28:03 -04:00
Kevin K
3312893dda docs: inter-links all types and pages
All doc pages should now be inter-linked between other doc pages and
Rust documentation.

Closes #505
2016-05-15 14:23:37 -04:00
Kevin K
52ca6505b4 docs: makes all publicly available types viewable in docs
Some types weren't viewable in the docs, such as `Values`, `OsValues`,
and `ArgSettings`. All these types should now be browsable in the
docs page.

Relates to #505
2016-05-13 18:52:29 -04:00
Hendrik Sollich
ac42f6cf0d Fix: SubCommand::aliases lifetime errors 2016-05-11 21:08:25 +02:00
Hendrik Sollich
6ba910e89b test: adds failing doc test 2016-05-11 20:16:56 +02:00
Kevin K
41a482cf5d imp(SubCommand Aliases): adds feature to yaml configs too 2016-05-10 17:15:06 -04:00
Kevin K
66b4dea65c feat(SubCommands): adds support for subcommand aliases
Allows adding a subcommand alias, which function as "hidden" subcommands that automatically
dispatch as if this subcommand was used. This is more efficient, and easier than creating
multiple hidden subcommands as one only needs to check for the existing of this command,
and not all vairants.

Example:

```
let m = App::new("myprog")
            .subcommand(SubCommand::with_name("test")
                .alias("do-stuff"))
            .get_matches_from(vec!["myprog", "do-stuff"]);
assert_eq!(m.subcommand_name(), Some("test"));
```

Example using multiple aliases:

```
let m = App::new("myprog")
            .subcommand(SubCommand::with_name("test")
                .aliases(&["do-stuff", "do-tests", "tests"]))
            .get_matches_from(vec!["myprog", "do-tests"]);
assert_eq!(m.subcommand_name(), Some("test"));
```

Closes #469
2016-05-10 15:21:19 -04:00
Kevin K
3ca0947c16 fix(Usage Strings): now properly dedups args that are also in groups
For example, if an arg is part of a required group, it will only appear
in the group usage string, and not in both the group as well as the arg
by itself.

Imagine a group containing two args, `arg1` and `--arg2`

OLD:
    `myprog <arg1> <arg1|--arg2>`

NEW:
    `myprog <arg1|--arg2>`

Closes #498
2016-05-09 19:14:11 -04:00
Kevin K
f574fb8a7c fix(Usage Strings): removes duplicate groups from usage strings 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
fef11154fb imp(Groups): formats positional args in groups in a better way 2016-05-08 21:33:27 -04:00
Kevin K
03dfe5ceff imp(Help): moves positionals to standard <> formatting 2016-05-08 20:37:51 -04:00
Kevin K
2efd81ebbc chore: clippy update and run 2016-05-06 17:59:52 -04:00
Kevin K
ffde90f2ba style: rustfmt run 2016-05-06 17:52:23 -04:00
Kevin K
5b7fe8e416 imp(Help): default help subcommand string has been shortened
Closes #494
2016-05-05 21:49:51 -04:00
Kevin K
5b0120088a fix(Required Args): fixes issue where missing required args are sometimes duplicatd in error messages
Closes #492
2016-05-03 16:31:55 -04:00
Kevin K
d8e4dbc961 feat(Help): adds support for displaying info before help message
Can now use the `App::before_help` method to add additional information
that will be displayed prior to the help message. Common uses are
copyright, or license information.
2016-05-03 16:31:55 -04:00
Kevin K
9fdad2e970 tests: adds tests for required_unless settings 2016-05-03 16:31:54 -04:00
Kevin K
7c89fc55ff docs(required_unless): adds docs and examples for required_unless 2016-05-03 16:31:54 -04:00
Kevin K
6987f37e71 feat(Required): adds allowing args that are required unless certain args are present
Adds three new methods of `Arg` which allow for specifying three new
types of rules.

* `Arg::required_unless`

Allows saying a particular arg is only required if a specific other arg
*isn't* present.

* `Arg::required_unless_all`

Allows saying a particular arg is only required so long as *all* the
following args aren't present

* `Arg::required_unless_one`

Allows saying a particular arg is required unless at least one of the
following args is present.
2016-05-03 16:31:54 -04:00
Kevin K
cb708093a7 docs: hides formatting from docs 2016-05-02 18:04:10 -04:00
Kevin K
4fe133d9ce chore: removes unused imports 2016-05-02 18:04:10 -04:00
Kevin K
770397bcb2 feat(HELP): implements optional colored help messages
To enable, ensure `clap` is compiled with `color` cargo feature.

Then in code use `AppSettings::ColoredHelp`

Closes #483
2016-04-18 00:05:43 -07:00
Homu
fdbd12e830 Auto merge of #478 - hgrecco:template, r=kbknapp
A new Help Engine with templating capabilities

This set of commits brings a new Help System to CLAP.

Major changes are:
- The help format is (almost) completely defined in `help.rs` instead of being scattered across multiple files.
- The HELP object contains a writer and its methods accept AnyArgs, not the other way around.
- A template option allows the user to change completely the organization of the autogenerated help.
2016-04-18 08:12:39 +09: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
8d23806bd6 fix(HELP): Adjust Help to semantic changes introduced in 6933b84 2016-04-13 07:06:23 -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
Hernan Grecco
a91d378ba0 imp(parser.rs): Provide a way to create a usage string without the USAGE: title 2016-04-13 07:06:22 -03:00
Hernan Grecco
9d757e8678 imp(macros.rs): Added write_nspaces macro (a new version of write_spaces)
`write_nspaces` has three differences with `write_spaces`

  1. Accepts arguments with attribute access (such as self.writer)
  2. The order of the arguments is swapped to make the writer the first
      argument as in other write related macros.
  3. Does not use the `write!` macro under the hood but rather calls
      directly `write`

I have chosen to put the function under a new name to avoid backwards
compatibility problem but it might be better to migrate everything to
`write_nspaces` (and maybe rename it `write_spaces`)
2016-04-13 07:06:22 -03:00
Hernan Grecco
65b3f66753 imp(srs/args): Added longest_filter to AnyArg trait
This function allows providing an extra filter to remove elements when finding
the longest element.
2016-04-13 07:06:22 -03:00
Hernan Grecco
d51945f8b8 imp(parser.rs): Make Parser's create_usage public allowing to have function outside the parser to generate the help 2016-04-13 07:06:22 -03:00
Hernan Grecco
9b23e7ee40 imp(parser.rs): Expose Parser's flags, opts and positionals argument as iterators
Writing the help requires read only access to Parser's flags, opts
and positionals. This commit provides 3 functions returning iterators
over those collections (`iter_*`) allowing to have function outside
the parser to generate the help.
2016-04-13 07:06:22 -03:00
Hernan Grecco
1321630ef5 imp(src/args): Exposes argument display order by introducing a new Trait
This commit introduces a new trait (`DispOrder`) with a single function
(`fn disp_order(&self) -> usize`). It is use to expose the display order
of an argument in a read-only manner.
2016-04-13 07:06:22 -03:00
Roman A. Taycher
d0f1d204a0 minor comment fixes 2016-04-11 22:37:36 -07:00
Roman A. Taycher
38fb59abf4 feat(Authors Macro): adds a crate_authors macro
Adds a crate_authors! macro that fetches
crate authors from a (recently added)
cargo enviromental variable populated
from the Cargo file. Like the
crate_version macro.

Closes #447
2016-04-11 16:17:44 -07:00
panicbit
3019a685ee Fix off-by-one-error in ArgGroup printing 2016-04-10 02:46:51 +02:00
Kevin K
71acf1d576 fix(Help Message): fixes bug where arg name is printed twice
Closes #472
2016-04-02 20:35:49 -04:00
Holger Rapp
4c676c06e8 Use ::std::result::Result to make macro hygienic. 2016-04-01 22:03:29 +02:00
Kevin K
885d166f04 fix(Empty Values): fixes bug where empty values weren't stored
Passing empty values, such as `--feature ""` now stores the empty string
correctly as a value (assuming empty values are allowed as per the arg
configuration)

Closes #470
2016-03-29 22:25:13 -04:00
Kevin K
d4b5545099 fix: fixes compiling with debug cargo feature 2016-03-29 22:24:34 -04:00
Kevin K
205b07bf2e fix(Help Subcommand): fixes issue where help and version flags weren't properly displayed
Closes #466
2016-03-28 11:26:56 -04:00
Kevin K
05365ddcc2 fix(Help Message): fixes bug with wrapping in the middle of a unicode sequence
Closes #456
2016-03-27 16:01:17 -04:00
Kevin K
6933b8491c fix(Usage Strings): fixes small bug where -- would appear needlessly in usage strings
Closes #461
2016-03-27 14:22:51 -04:00
Kevin K
144e7e29d6 chore: clippy run 2016-03-22 21:16:53 -04:00
Kevin K
813d75d06f feat(Help Message): wraps and aligns the help message of subcommands
Subcommand's help strings are now automatically wrapped and aligned just
like other arguments.

Closes #452
2016-03-16 10:17:00 -04:00
Kevin K
1d73b03552 fix(Help Message): fixes a bug where small terminal sizes causing a loop
Now if the terminal size is too small to properly wrap the help text
lines, it will default to just wrapping normalling as it should.

This is determined on a per help text basis, so because the terminal
size is too small for a single argument's help to wrap properly, all
other arguments will still wrap and align correctly. Only the one
affected argument will not align properly.

Closes #453
2016-03-16 08:55:42 -04:00
Kevin K
2c12757bbd feat(Help Subcommand): adds support passing additional subcommands to help subcommand
The `help` subcommand can now accept other subcommands as arguments to
display their help message. This is similar to how many other CLIs
already perform. For example:

```
$ myprog help mysubcmd
```

Would print the help message for `mysubcmd`. But even more, the `help`
subcommand accepts nested subcommands as well, i.e. a grandchild
subcommand such as

```
$ myprog help child grandchild
```

Would print the help message of `grandchild` where `grandchild` is a
subcommand of `child` and `child` is a subcommand of `myprog`.

Closes #416
2016-03-14 22:41:47 -04:00
Kevin K
031b71733c chore: fixes platform dependant libc calls 2016-03-14 08:00:11 -04:00
Kevin K
d46eaa2cd6 style: fix formatting 2016-03-14 07:53:23 -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
e36af02666 feat(Help Message): can auto wrap and aligning help text to term width
By default `clap` now automatically wraps and aligns help strings to the
term width. i.e.

```
    -o, --option <opt>    some really long help
text that should be auto aligned but isn't righ
t now
```

Now looks like this:

```
    -o, --option <opt>    some really long help
                          text that should be
                          auto aligned but isn't
                          right now
```

The wrapping also respects words, and wraps at spaces so as to not cut
words in the middle.

This requires the `libc` dep which is enabled (by default) with the
`wrap_help` cargo feature flag.

Closes #428
2016-03-13 22:07:28 -04:00
Kevin K
c5c58c86b9 fix(From Usage): fixes a bug where adding empty lines werent ignored 2016-03-10 16:36:23 -05:00
Kevin K
22000a08f7 chore: changes some assertions to debug assertions 2016-03-10 16:33:39 -05:00
Kevin K
ad86e43334 feat(Settings): adds support for automatically deriving custom display order of args
Args and subcommands can now have their display order automatically
derived by using the setting `AppSettings::DeriveDisplayOrder` which
will display the args and subcommands in the order that they were
declared in, instead of alphabetical order which is the default.

Closes #444
2016-03-10 16:32:02 -05:00
Kevin K
927d1da1c7 chore: ignore failing clippy build 2016-03-09 19:54:42 -05:00
Kevin K
06c729f52f chore: fixes failing nightly lint 2016-03-09 18:40:31 -05:00
Kevin K
4ff0205b85 docs(Groups): explains required ArgGroups better
Closes #439
2016-03-09 20:16:52 -05:00
Kevin K
e41a2f1bea test: fixes failing doc tests 2016-03-09 20:14:35 -05:00
Kevin K
7d2a2ed413 feat(Subcommands): adds support for custom ordering in help messages
Allows custom ordering of subcommands within the help message. Subcommands with a lower
value will be displayed first in the help message. This is helpful when one would like to
emphasise frequently used subcommands, or prioritize those towards the top of the list.
Duplicate values **are** allowed. Subcommands with duplicate display orders will be
displayed in alphabetical order.

**NOTE:** The default is 999 for all subcommands.

```rust
use clap::{App, SubCommand};
let m = App::new("cust-ord")
    .subcommand(SubCommand::with_name("alpha") // typically subcommands are grouped
                                               // alphabetically by name. Subcommands
                                               // without a display_order have a value of
                                               // 999 and are displayed alphabetically with
                                               // all other 999 subcommands
        .about("Some help and text"))
    .subcommand(SubCommand::with_name("beta")
        .display_order(1)   // In order to force this subcommand to appear *first*
                            // all we have to do is give it a value lower than 999.
                            // Any other subcommands with a value of 1 will be displayed
                            // alphabetically with this one...then 2 values, then 3, etc.
        .about("I should be first!"))
    .get_matches_from(vec![
        "cust-ord", "--help"
    ]);
```

The above example displays the following help message

```
cust-ord

USAGE:
    cust-ord [FLAGS] [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    beta    I should be first!
    alpha   Some help and text
```

Closes #442
2016-03-09 19:43:53 -05:00
Kevin K
9803b51e79 feat(Opts and Flags): adds support for custom ordering in help messages
Allows custom ordering of args within the help message. Args with a lower value will be
displayed first in the help message. This is helpful when one would like to emphasise
frequently used args, or prioritize those towards the top of the list. Duplicate values
**are** allowed. Args with duplicate display orders will be displayed in alphabetical
order.

**NOTE:** The default is 999 for all arguments.

**NOTE:** This setting is ignored for positional arguments which are always displayed in
index order.

```rust
use clap::{App, Arg};
let m = App::new("cust-ord")
    .arg(Arg::with_name("a") // typically args are grouped by alphabetically by name
                             // Args without a display_order have a value of 999 and are
                             // displayed alphabetically with all other 999 args
        .long("long-option")
        .short("o")
        .takes_value(true)
        .help("Some help and text"))
    .arg(Arg::with_name("b")
        .long("other-option")
        .short("O")
        .takes_value(true)
        .display_order(1)   // Let's force this arg to appear *first*
                            // all we have to do is give it a value lower than 999
                            // any other args with a value of 1 would be displayed
                            // alphabetically with other 1 args. Then 2, then 3, etc.
        .help("I should be first!"))
    .get_matches_from(vec![
        "cust-ord", "--help"
    ]);
```

The above example displays the following help message

```
cust-ord

USAGE:
    cust-ord [FLAGS] [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -O, --other-option <b>    I should be first!
    -o, --long-option <a>     Some help and text
```
2016-03-09 19:41:43 -05:00
Alexander Bulaev
150784ae20 Update VecMap to 0.6 2016-03-08 19:50:20 -05:00
Kevin K
deace34ad2 chore: clippy run 2016-03-08 10:39:43 -05:00
Jorge Aparicio
56d14cbbb6 fix clippy warnings 2016-02-22 18:36:57 -05:00
Jorge Aparicio
6c851f4314 sprinkle #[derive(Copy)] 2016-02-21 11:45:19 -05:00
Jorge Aparicio
9a94ad8ad6 sprinkle #[allow(missing_debug_implementations)] 2016-02-21 11:44:45 -05:00
Jorge Aparicio
d752c17029 rename OsStrExt2::{is_empty,len} to {is_empty_,len_}
OsStr recently gained unstable inherent methods with the same name. This rename
makes sure we don't call the inherent methods but the methods provided by this
extension trait.
2016-02-21 11:18:26 -05:00
Kevin K
a834ae6990 chore: hides ArgSettings in docs 2016-02-19 01:47:37 -05:00
Kevin K
3c8db0e9be docs(AppSettings): clarifies that AppSettings do not propagate
Closes #429
2016-02-19 01:47:37 -05:00
Kevin K
e2ec5f09eb chore: clippy run 2016-02-19 01:47:37 -05:00
Kevin K
1e79cccc12 docs(Arg Examples): adds better examples 2016-02-19 01:47:37 -05:00
Kevin K
066df7486e imp(Help): adds setting for next line help by arg
Adds a setting for both `AppSettings` and an `Arg` method which allows
placing the help text for a particular argument (or all arguments via
the `AppSettings`) on the line after the argument itself and indented
once.

This is useful for when a single argument may have a very long
invocation flag, or many value names which throws off the alignment of
al other arguments. On a small terminal this can be terrible. Placing
the text on the line below the argument solves this issue. This is also
how many of the GNU utilities display their help strings for individual
arguments.

The final caes where this can be hepful is if the argument has a very
long or detailed and complex help string that will span multiple lines.
It can be visually more appealing and easier to read when those lines
don't wrap as frequently since there is more space on the next line.

Closes #427
2016-02-17 23:47:27 -05:00
Kevin K
b37c010c1b imp(Default Values): displays the default value in the help text 2016-02-14 01:11:06 -05:00
Kevin K
1153e8af60 chore: clippy run 2016-02-14 01:10:44 -05:00
Kevin K
9facd74f84 docs(Default Values): adds better examples and notes for default values 2016-02-10 12:39:44 -05:00
Kevin K
7321195296 feat(Defult Values): adds support for default values in args
Closes #418
2016-02-10 10:56:58 -05:00
Kevin K
5460778f56 tests: adds tests for displaying positional args with value names 2016-02-09 09:29:23 -05:00
Kevin K
f0a99916c5 imp(Positional Arguments): now displays value name if appropriate
When value names are use, they will be displayed in help and error
messages instead of the argument name. For example, an argument named
`arg` but with the value name `FILE` will be displayed as `[FILE]`.
Likewise multiple value names will be displayed properly such as `[FILE1] [FILE2]`

Closes #420
2016-02-09 09:27:17 -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
72c387da0b fix(Multiple Values): fixes bug where number_of_values wasnt respected
i.e. assume, option -O set to multiple, and number_of_values(1)
set. And assume a *required* positional argument is also set.

-O some -O other pos

Would fail with pos arg not supplied.

Relates to #415
2016-02-04 19:38:17 -05:00
Kevin K
a62e452754 fix(AppSettings): fixes bug where subcmds didn't receive parent ver
Subcommands now receive the parent version when the setting
AppSettings::GlobalVersion has been set.
2016-02-04 11:54:46 -05:00
Kevin K
8bcbce27f7 tests(Suggestions): adds additional tests 2016-02-04 02:01:10 -05:00
Kevin K
7166f4f110 refactor(macros): removes ok() from Result.ok().expect() 2016-02-04 02:01:10 -05:00
Kevin K
2bc1908320 tests(ArgGroup): adds additional tests including YAML 2016-02-04 02:01:10 -05:00
Kevin K
fcbc7e12f5 fix: adds support for building ArgGroups from standalone YAML
ArgGroups can now be built from standalone YAML documents. This is
labeled as a fix because it should have been the case prior. A
standalone YAML document for a group would look something like

```
name: test
args:
    - arg1
    - arg2
required: true
conflicts:
    - arg3
requires:
    - arg4
```

This commit also keeps support building groups as part of a larger
entire App YAML document where the name is specified as a key to the
yaml tree
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
c19a791745 imp(values): adds support for up to u64::max values per arg 2016-02-02 07:45:49 -05:00
Kevin K
d431417003 refactor(macros): does some code deduplication by macros 2016-02-02 07:45:49 -05:00
Kevin K
2704b300ec refactor(macros): implements a slightly better arg_post_processing 2016-02-02 07:45:49 -05:00
Kevin K
8f145f1024 refactor(macros): implements a better _handle_group_reqs 2016-02-02 07:45:49 -05:00
Kevin K
de32078d75 refactor(macros): implements a better vec_remove and remove_overriden 2016-02-02 07:45:49 -05:00
Kevin K
ca7f197a12 refactor: minor code cleanup 2016-02-02 07:45:49 -05:00
Kevin K
cdee7a0eb2 feat(AppSettings): adds HidePossibleValuesInHelp to skip writing those values 2016-02-02 07:21:01 -05:00
Kevin K
be2cbd9480 fix(App::args_from_usage): skips empty lines when parsing multiple lines from usage 2016-02-02 07:21:01 -05:00
Kevin K
ee96baffd3 fix(value_t_or_exit): fixes typo which causes value_t_or_exit to return a Result 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
ab41be700b imp(arg_enum): enum declared with arg_enum returns [&'static str; #] instead of Vec 2016-01-31 08:23:34 -05:00
Kevin K
c19c17a885 fix(SubCommands): fixed where subcmds weren't recognized after mult args
Closes #405
2016-01-31 07:35:42 -05:00
Kevin K
0bcc712064 fix(Usage Parser): fixes a bug where literal single quotes weren't allowed in help strings
Closes #406
2016-01-31 07:12:07 -05:00
Vincent Prouillet
0c8b84af61 fix: clap_app! should be gated by unstable, not nightly feature 2016-01-30 11:16:13 +00:00
Kevin K
90542747ac chore: fixes doc and style mistakes 2016-01-28 21:58:40 -05:00
Kevin K
c28d24db3e fix: fixes nightly build with new lints 2016-01-28 11:46:12 -05:00
Kevin K
d182049119 chore: fixes failing rustdoc 2016-01-28 11:46:12 -05:00
Kevin K
a210f89b84 docs: updates examples for 2x release
Closes #394
2016-01-28 11:46:12 -05:00
Kevin K
518b89bd3d fix: fixes Windows build for 2x release
Closes #392
2016-01-28 11:46:12 -05:00
Kevin K
2031682193 chore: updates additional files for 2x release 2016-01-28 11:46:12 -05:00
Kevin K
d2a78e3e21 docs: updates documentation for v2 release 2016-01-28 11:45:31 -05:00
Kevin K
693aece2cb fix: fixes yaml build for 2x base 2016-01-28 11:45:31 -05:00
Kevin K
4c37b26a84 tests: fixes some failing doc tests 2016-01-28 11:45:31 -05:00
Kevin K
e494672ffc refactor: removes some unnecessary code checks 2016-01-28 11:45:31 -05:00
Kevin K
f1876388a7 docs: updating docs for 2x release 2016-01-28 11:45:31 -05:00
Kevin K
609c06e119 feat: adds support for external subcommands
External subcommands are now supported via the following:

```rust
extern crate clap;
use clap::{App, AppSettings};

fn main() {
    // Assume there is a third party subcommand named myprog-subcmd
    let m = App::new("myprog")
        .setting(AppSettings::AllowExternalSubcommands)
        .get_matches_from(vec![
            "myprog", "subcmd", "--option", "value", "-fff", "--flag"
        ]);
    // All trailing arguments will be stored under the subcommands sub-matches under a
    // value of their runtime name (in this case "subcmd")
    match m.subcommand() {
        (external, Some(ext_m)) => {
            let ext_args: Vec<&str> = ext_m.values_of(external).unwrap().collect();
            assert_eq!(ext_args ,["--option", "value", "-fff", "--flag"]);
        },
        _ => unreachable!()
   }
}
```

Closes #372
2016-01-28 11:45:31 -05:00
Kevin K
86f3e33975 refactor(macros): uses macros to implement Settings enums 2016-01-28 11:45:31 -05:00
Kevin K
26ecadd252 feat: adds support values with a leading hyphen
By using AppSettings::AllowLeadingHyphen values starting with a
leading hyphen (such as a negative number) are supported. This
setting should be used with caution as it silences certain
circumstances which would otherwise be an error (like forgetting
a value to an option argument).

Closes #385
2016-01-28 11:45:31 -05:00
Kevin K
35ad17a282 feat: adds support for turning off the value delimiter
Closes #352
2016-01-28 11:45:31 -05:00
Kevin K
0871145245 feat: adds support changing the value delimiter
Closes #353
2016-01-28 11:45:31 -05:00
Kevin K
c2e03a0a4e feat: adds support for comma separated values
This commit adds support for values separated by commas such as
--option=val1,val2,val3. It also includes support for uses
without the equals and shorts (both with and without)

--option=val1,val2
--option val1,val2
-oval1,val2
-o=val1,val2
-o val1,val2

Closes #348
2016-01-28 11:45:31 -05:00
Kevin K
4192e1acea test(Yaml): fixes yaml tests 2016-01-28 11:45:31 -05:00
Kevin K
eb4de9215f imp(From Usage): vastly improves the usage parser
Closes #350
2016-01-28 11:45:31 -05:00
Kevin K
95e8209712 feat: adds support with options with optional values
Closes #367
2016-01-28 11:45:31 -05:00
Kevin K
0eba835968 tests: updated python tests to v2 info 2016-01-28 11:45:31 -05:00
Kevin K
d707fa0fad tests(v2): updating yaml tests to new v2 base 2016-01-28 11:45:31 -05:00
Kevin K
0410873d8d chore: clippy run 2016-01-28 11:45:31 -05:00
Kevin K
bb52d2d194 chore: removes unneeded function 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
Kevin K
20de5c6e76 feat(v2): implementing the base of 2.x
This commit implements the base changes for clap 2.x
2016-01-28 11:45:31 -05:00
Kevin K
d3a4834225 chore: fix failing nightly 2016-01-27 10:09:29 -05:00
messense
f0a0e4df50 docs(App) Fix App.print_help documentation 2016-01-10 16:44:24 +08:00
Kevin K
c9bf7e4440 fix: fixes an issue where invalid short args didn't cause an error
Closes #368
2016-01-03 22:54:13 -05:00
Kevin K
8f3817f665 fix: prints the name in version and help instead of binary name 2016-01-03 22:51:01 -05:00
Kevin K
ea83a3d421 fix: fixes an intentional panic issue discovered via clippy 2016-01-03 21:54:56 -05:00
Kevin K
55041bc878 chore: updates clippy 2015-12-19 05:35:44 -05:00
Kevin K
b9ff14bfff chore: changes build command features for Windows builds in testing 2015-12-18 09:01:59 -05:00
Kevin K
2b6511fe65 tests(fmt): removes fmt tests from Windows builds 2015-12-18 09:01:59 -05:00
Kevin K
faad83fbef fix: ArgRequiredElseHelp setting now takes precedence over missing required args
Closes #362
2015-12-17 23:51:57 -05:00
Sung Rim Huh
5ba8ba9dcc fix(errors): return correct error type in WrongNumValues error builder 2015-12-10 08:40:24 -08:00
Kevin K
99cdebc23d imp: clippy improvements 2015-12-08 05:17:30 -05:00
Kevin K
c4d2b17119 fix(Errors): fixes some instances when errors are missing a final newline 2015-11-20 08:23:39 -05:00
Kevin K
a35f76346f fix(Errors): fixes a compiling bug when built on Windows or without the color feature
Close #345
2015-11-14 04:51:44 -05:00
Kevin K
f03b88a976 fix(Required Args): fixes a bug where required args are not correctly accounted for
Closes #343
2015-11-13 09:34:26 -05:00
Kevin K
3359683380 refactor(Defaults): derives traits instead of manual implementation 2015-11-12 22:43:37 -05: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
5800cdec6d imp(Traits): refactoring some configuration into traits
There is now an AnyArg trait which lets you (clap dev, not consumer) get
info about certain args regardless of their type. Allows more generic
and de-duplicated code
2015-11-11 08:48:34 -05:00
Kevin K
1fdecfd519 style: moves mod names to follow rust standards 2015-11-09 07:17:23 -05:00
Kevin K
f5bfb41bf1 refactor: moves value validation out of App and into Option Args 2015-11-09 03:49:20 -05:00
Kevin K
1b69ca4bee refactor: moves code for ergonomics 2015-11-09 03:48:49 -05:00
Kevin K
bf4d8417b8 style: rustfmt run 2015-11-09 02:22:12 -05:00
Kevin K
c6858f7875 fix: fixes a bug with required positional args in usage strings 2015-11-09 02:01:21 -05:00
Kevin K
447786ed8a refactor(Usage): fixes some error handling duplication 2015-11-08 09:55:02 -05:00
Kevin K
bc4495b32e perf(App): more BTreeMap->Vec, Opts and SubCmds 2015-11-08 03:48:13 -05:00
Kevin K
d357640fab perf(App): changes flags BTreeMap->Vec 2015-11-08 01:50:12 -05:00
Kevin K
78971fd68d perf(App): removed unneeded BTreeMap 2015-11-08 01:08:06 -05:00
Kevin K
64b921d087 perf(App): changes BTreeMap to VecMap in some instances 2015-11-08 01:01:11 -05:00
Kevin K
111745c937 chore: updates clippy 2015-11-07 00:08:15 -05:00
Kevin K
cdc29175bc imp: massive errors overhaul 2015-11-03 08:26:17 -05:00
Kevin K
e59bc0c160 imp(Errors): errors have been vastly improved 2015-11-03 02:09:49 -05:00
Kevin K
ec0089d42e perf(App): removed excess clones 2015-11-03 02:07:57 -05:00
Kevin K
19538b9c22 chore: fixes features declarations 2015-11-03 01:59:08 -05:00
Kevin K
b261783c71 refactor(UsageParser): moves code for readability 2015-11-03 01:59:08 -05:00
Kevin K
89b51fdf8b fix(Error Status): fixes bug where --help and --version return non-zero exit code 2015-11-02 22:56:05 -05:00
Ben S
00b61ae226 Fix a bunch of typos in comments 2015-11-01 14:02:37 +00:00
Jimmy Cuadra
434f497ab6 docs: Clarify behavior of Arg::multiple with options. 2015-10-29 22:40:47 -07:00
Jimmy Cuadra
c1f66b5de7 docs: Fix typos and improve grammar. 2015-10-29 22:40:10 -07:00
Kevin K
1a8bf31e7a docs: adds comparison in readme
Closes #325
2015-10-29 01:07:43 -04:00
Kevin K
27df8b9d98 fix(Versionless SubCommands): fixes a bug where the -V flag was needlessly built
Closes #329
2015-10-29 00:23:09 -04:00
Kevin K
e639adad22 style: removes commented out code 2015-10-28 11:00:31 -04:00
Kevin K
d0c13d2960 style: rustfmt run 2015-10-28 10:56:10 -04:00
Kevin K
f161ffa470 chore: updates and implements lint findings 2015-10-28 10:55:26 -04: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
c47025dca2 fix(Safe Matches): using 'safe' forms of the get_matches family no longer exit the process
Closes #256
2015-10-28 05:55:04 -04:00
Kevin K
c9a9548a8f fix(Option Args): fixes bug with args and multiple values
Closes #323
2015-10-28 04:54:28 -04:00
Kevin K
e3be87cfc0 fix(Help and Version): only builds help and version once 2015-10-28 00:25:40 -04:00
Kevin K
34ce59ede5 fix(Errors): tones down quoting in some error messages
Closes #309
2015-10-13 13:46:35 -04:00
Kevin K
c78ce128eb fix: fixes crash on invalid arg error 2015-10-06 15:08:59 -04:00
Kevin K
6b90f1adad refactor(Errors): refactors how errors are created for deduplication
Closes #277
2015-10-05 21:47:39 -07:00
Kevin K
2a223dad82 fix(Unified Help): sorts both flags and options as a unified category 2015-10-05 20:36:30 -04:00
Georg Brandl
e73b07e194 fix: grammar error in some conflicting option errors 2015-10-04 10:43:59 +02:00
Kevin K
72b453dc17 fix(Usage): fixes a bug where required args aren't filtered properly
Closes #277
2015-10-03 09:22:15 -04:00
Kevin K
0e3733e4fe feat: supports -aValue style options 2015-10-02 16:46:37 -04:00
SungRim Huh
b7df92d7ea docs: clean up some formatting 2015-10-01 21:46:45 -04:00
SungRim Huh
d7233bf122 docs: move the crate-level docs to top of the lib.rs file 2015-10-01 16:48:25 -07:00
Kevin K
3183279acd Merge branch 'master' into rustdoc 2015-10-01 17:30:47 -04:00
Kevin K
34b601be5f docs: changes doc comments to rustdoc comments 2015-10-01 17:27:29 -04:00
Kevin K
0005154bcb Merge branch 'master' into issue-278 2015-10-01 14:28:09 -04:00
Kevin K
27018b1821 feat(Trailing VarArg): adds opt-in setting for final arg being vararg
Closes #278
2015-10-01 14:18:17 -04:00
Kevin K
05414a4b6d style: removes trailing whitespace 2015-10-01 14:16:02 -04:00
Kevin K
0f411c1c3e Merge branch 'master' into issue-298
skip-ci
2015-10-01 12:49:27 -04:00
Kevin K
aaf0d6fe7a fix(Usage Strings): fixes a bug ordering of elements in usage strings
Closes #298
2015-10-01 12:33:37 -04:00
Kevin K
6f9ee181e6 docs(Rustdoc): adds portions of the readme to main rustdoc page
Closes #293
2015-10-01 12:03:14 -04:00
Kevin K
958ebb8629 refactor: removes legacy panics and fixes grammar 2015-10-01 00:05:41 -04:00
Kevin K
a9aae2ade4 refactor: fixes a typo in the arg settings 2015-09-30 23:59:40 -04:00
Kevin K
f1031dac13 refactor: fixes a typo in the app settings 2015-09-30 23:59:40 -04:00