Commit graph

1210 commits

Author SHA1 Message Date
Kevin K
89db52a965 chore: increase version 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
84381b577e Merge pull request #490 from nvzqz/master
chore: Fix typos in README.md
2016-05-02 22:01:07 -04:00
Nikolai Vazquez
e6cb68709d chore: Fix typos in README.md 2016-04-21 00:51:09 -04:00
Homu
94b33c5aea Auto merge of #488 - flying-sheep:patch-1, r=kbknapp
Revert accidental pasting

There was an URL accidentally pasted at the wrong position in 8a95dace62
2016-04-19 10:09:19 +09:00
Philipp A
bd13ab02d7 Revert accdental pasting
There was an URL accidentally pasted at the wrong position in 8a95dace62
2016-04-18 12:53:02 +02:00
Homu
25d5cbc238 Auto merge of #487 - kbknapp:issue-483, r=kbknapp
Issue 483
2016-04-18 13:49:46 +09: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
Kevin K
c4ffd2a9ce chore: updates contributors 2016-04-18 00:05:43 -07:00
Kevin K
ee41482608 chore: increase version 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
Homu
93a07e36f7 Auto merge of #482 - rtaycher:authors, r=kbknapp
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

Hopefully this fixed the previous problems.
2016-04-18 07:29:05 +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
ac46864381 move import inside function to avoid conditional compilation warning 2016-04-11 16:49:39 -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
Homu
d9372d09bf Auto merge of #481 - kbknapp:v2.2.6, r=kbknapp
chore: increase version
2016-04-12 02:32:05 +09:00
Kevin K
8a95dace62 chore: increase version 2016-04-11 11:50:38 -07:00
Homu
eb5b29912f Auto merge of #479 - kbknapp:issue-476, r=kbknapp
Issue 476

From #477

Closes #476
2016-04-11 09:50:32 +09:00
Kevin K
c3795ad404 tests(Groups): removes tests causing issues that werent required 2016-04-09 22:33:49 -07:00
panicbit
3019a685ee Fix off-by-one-error in ArgGroup printing 2016-04-10 02:46:51 +02:00
Homu
1dd7e56632 Auto merge of #475 - kbknapp:updates, r=kbknapp
chore: updates deps
2016-04-09 09:52:46 +09:00
Kevin K
00d5a3e0b2 chore: updates deps 2016-04-08 11:40:38 -07:00
Homu
bad00f62ed Auto merge of #474 - kbknapp:issue-472, r=kbknapp
Issue 472
2016-04-03 23:58:42 +09:00
Homu
336d76e030 Auto merge of #473 - SirVer:fix_result, r=kbknapp
Use ::std::result::Result to make macro hygienic.

I ran into an error using

```
struct Error {}

pub type Result<T> = ::std::result::Result<T, Error>;

arg_enum!{
   ....
}
~~~

Attached is a fix.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/kbknapp/clap-rs/473)
<!-- Reviewable:end -->
2016-04-03 10:52:45 +09:00
Kevin K
616e803321 chore: increase version 2016-04-02 20:50:47 -04:00
Kevin K
0e69314e53 test(Help Message): adds test to prevent issue-472 2016-04-02 20:47:27 -04: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
Homu
fa02d3b33b Auto merge of #471 - kbknapp:issue-470, r=kbknapp
Issue 470

Relates to [multirust-rs 190](https://github.com/rust-lang-nursery/multirust-rs/issues/190)
2016-03-30 12:02:42 +09:00
Kevin K
e923c2c153 chore: increase version' 2016-03-29 22:32:15 -04:00
Kevin K
baf0e18095 tests(Empty Values): adds tests for empty values 2016-03-29 22:31:40 -04: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
Homu
157f981b09 Auto merge of #467 - kbknapp:issue-466, r=kbknapp
fix(Help Subcommand): fixes issue where help and version flags weren'…

…t properly displayed

Closes #466
2016-03-29 11:38:05 +09:00
Kevin K
34ffba2803 Merge branch 'master' into issue-466 2016-03-28 21:52:50 -04:00