You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-22
Original file line number
Diff line number
Diff line change
@@ -50,14 +50,16 @@ Below are a few of the features which `clap` supports, full descriptions and usa
50
50
***Specific Value Sets**: Positional or Option Arguments can optionally define a specific set of allowed values (i.e. imagine a `--mode` option which may *only* have one of two values `fast` or `slow` such as `--mode fast` or `--mode slow`)
51
51
***Default Values**: Although not specifically provided by `clap` you can achieve this exact functionality from Rust's `Option<&str>.unwrap_or("some default")` method (or `Result<T,String>.unwrap_or(T)` when using typed values)
52
52
***Automatic Version from Cargo.toml**: `clap` is fully compatible with Rust's `env!()` macro for automatically setting the version of your application to the version in your Cargo.toml. See `examples/09_AutoVersion.rs` for how to do this (Thanks to [jhelwig](https://github.com/jhelwig) for pointing this out)
53
-
***Typed Values**: You can use several convenience macros provided by `clap` to get typed values (i.e. `i32`, `u8`, etc.) from positional or option arguments so long as the type you request implements `std::str::FromStr` See the `examples/12_TypedValues.rs`. You can also use `clap`s `simple_enum!` or `arg_enum!` macro to create an enum with variants that automatically implements `std::str::FromStr`. See `examples/13a_EnumValuesAutomatic.rs` for details.
53
+
***Typed Values**: You can use several convenience macros provided by `clap` to get typed values (i.e. `i32`, `u8`, etc.) from positional or option arguments so long as the type you request implements `std::str::FromStr` See the `examples/12_TypedValues.rs`. You can also use `clap`s `simple_enum!` or `arg_enum!` macro to create an enum with variants that automatically implements `std::str::FromStr`. See `examples/13a_EnumValuesAutomatic.rs` for details and performs an ascii case insensitive parse from a `string`->`enum`.
54
+
***Suggestions**: Suggests corrections when the user enter's a typo. For example, if you defined a `--myoption <value>` argument, and the user mistakenly typed `--moyption value` (notice `y` and `o` switched), they would receive a `Did you mean '--myoption' ?` error and exit gracefully. This also works for subcommands and flags. (Thanks to [Byron](https://github.com/Byron) for the implementation) (This feature can optionally be disabled, see 'Optional Dependencies / Features')
55
+
***Colorized (Red) Errors**: Error message are printed in red text (this feature can optionally be disabled, see 'Optional Dependencies / Features').
54
56
55
57
## Quick Example
56
-
58
+
57
59
The following two examples show a quick example of some of the very basic functionality of `clap`. For more advanced usage, such as requirements, exclusions, groups, multiple values and occurrences see the [video tutorials](https://www.youtube.com/playlist?list=PLza5oFLQGTl0Bc_EU_pBNcX-rhVqDTRxv), [documentation](http://kbknapp.github.io/clap-rs/clap/index.html), or `examples/` directory of this repository.
58
-
60
+
59
61
*NOTE:* Both examples are functionally the same, but show two different styles in which to use `clap`
60
-
62
+
61
63
```rust
62
64
// (Full example with detailed comments in examples/01a_QuickExample.rs)
63
65
//
@@ -85,21 +87,21 @@ fn main() {
85
87
// Calling .unwrap() is safe here because "INPUT" is required (if "INPUT" wasn't
86
88
// required we could have used an 'if let' to conditionally get the value)
The following example is functionally the same as the one above, but this method allows more advanced configuration options (not shown in this small example), or even dynamically generating arguments when desired. Both methods can be used together to get the best of both worlds (see the documentation, examples, or video tutorials).
117
-
119
+
118
120
```rust
119
121
// (Full example with detailed comments in examples/01b_QuickExample.rs)
120
122
//
121
-
// This example demonstrates clap's full 'builder pattern' style of creating arguments which is
123
+
// This example demonstrates clap's full 'builder pattern' style of creating arguments which is
122
124
// more verbose, but allows easier editting, and at times more advanced options, or the possibility
123
125
// to generate arguments dynamically.
124
126
externcrate clap;
@@ -154,21 +156,21 @@ fn main() {
154
156
// Calling .unwrap() is safe here because "INPUT" is required (if "INPUT" wasn't
155
157
// required we could have used an 'if let' to conditionally get the value)
@@ -227,7 +229,7 @@ To try out the pre-built example use the following stes:
227
229
To test out `clap`'s default auto-generated help/version follow these steps:
228
230
* Create a new cargo project `$ cargo new fake --bin && cd fake`
229
231
* Add `clap` to your `Cargo.toml`
230
-
*
232
+
*
231
233
```toml
232
234
[dependencies]
233
235
clap = "*"
@@ -268,6 +270,32 @@ Define a list of valid arguments for your program (see the [documentation](https
268
270
269
271
Then run `cargo build` or `cargo update && cargo build` for your project.
270
272
273
+
### Optional Dependencies / Features
274
+
275
+
If you'd like to keep your dependency list to **only**`clap`, you can disable any features that require an additional dependency. To do this, add this to your `Cargo.toml`:
276
+
277
+
```toml
278
+
[dependencies.clap]
279
+
version = "*"
280
+
default-features = false
281
+
```
282
+
283
+
You can also selectively enable only the features you'd like to include, by adding:
284
+
285
+
```toml
286
+
[dependencies.clap]
287
+
version = "*"
288
+
default-features = false
289
+
290
+
# Cherry-pick the features you'd like to use
291
+
features = [ "suggestions", "color" ]
292
+
```
293
+
294
+
The following is a list of optional `clap` features:
295
+
296
+
***"suggestions"**: Turns on the `Did you mean '--myoption' ?` feature for when users make typos.
297
+
***"color"**: Turns on red error messages.
298
+
271
299
### More Information
272
300
273
301
You can find complete documentation on the [github-pages site](http://kbknapp.github.io/clap-rs/clap/index.html) for this project.
@@ -292,17 +320,16 @@ Contributions are always welcome! And there is a multitude of ways in which you
292
320
4. Make your changes, and commit (`git commit -am "your message"`) (I try to use a [conventional](https://github.com/ajoslin/conventional-changelog/blob/master/CONVENTIONS.md) changelog format so I can update it using [clog](https://github.com/thoughtram/clog))
293
321
5. If applicable, run the tests (See below)
294
322
6. Push your changes back to your fork (`git push origin your-branch`)
295
-
7. Create a pull request! (You can also create the pull request right away, and we'll merge when ready. This a good way to discuss proposed changes.)
323
+
7. Create a pull request! (You can also create the pull request right away, and we'll merge when ready. This a good way to discuss proposed changes.)
296
324
297
325
Another really great way to help is if you find an interesting, or helpful way in which to use `clap`. You can either add it to the `examples/` directory, or file an issue and tell me. I'm all about giving credit where credit is due :)
298
326
299
327
### Running the tests
300
328
301
-
If contributing, you can run the tests as follows (assuming you've cloned the repo to `clap-rs/`
329
+
If contributing, you can run the tests as follows (assuming you're in the `clap-rs` directory)
302
330
303
331
```
304
-
cd clap-rs && cargo test
305
-
cd clap-tests && make test
332
+
cargo test && make -C clap-tests test
306
333
```
307
334
308
335
### Goals
@@ -331,7 +358,7 @@ Although I do my best to keep breaking changes to a minimum, being that this a s
+ No longer take a `Vec<&str>`, instead they take a generic `IntoIterator<Item=AsRef<str>>` which means you cannot use an inline `vec![]` but it means the methods are now far more flexible, especially for dynamic value generation.
333
360
+ Instead use something that conforms to the `IntoIterator` trait, or something like:
Copy file name to clipboardExpand all lines: src/lib.rs
+35-7
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
1
#![crate_type= "lib"]
2
2
3
+
// DOCS
3
4
//! # clap
4
5
//!
5
6
//!  []() []() [](https://gitter.im/kbknapp/clap-rs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -18,7 +19,7 @@
18
19
//!
19
20
//! ## Features
20
21
//!
21
-
//! Below are a few of the features which `clap` supports, full descriptions and usage can be found in the [documentation](http://kbknapp.github.io/clap-rs/docs/clap/index.html) and `examples/` directory
22
+
//! Below are a few of the features which `clap` supports, full descriptions and usage can be found in the [documentation](http://kbknapp.github.io/clap-rs/clap/index.html) and `examples/` directory
22
23
//!
23
24
//! * **Auto-generated Help, Version, and Usage information**
24
25
//! - Can optionally be fully, or partially overridden if you want a custom help, version, or usag
@@ -52,11 +53,13 @@
52
53
//! * **Specific Value Sets**: Positional or Option Arguments can optionally define a specific set of allowed values (i.e. imagine a `--mode` option which may *only* have one of two values `fast` or `slow` such as `--mode fast` or `--mode slow`)
53
54
//! * **Default Values**: Although not specifically provided by `clap` you can achieve this exact functionality from Rust's `Option<&str>.unwrap_or("some default")` method (or `Result<T,String>.unwrap_or(T)` when using typed values)
54
55
//! * **Automatic Version from Cargo.toml**: `clap` is fully compatible with Rust's `env!()` macro for automatically setting the version of your application to the version in your Cargo.toml. See `examples/09_AutoVersion.rs` for how to do this (Thanks to [jhelwig](https://github.com/jhelwig) for pointing this out)
55
-
//! * **Typed Values**: You can use several convenience macros provided by `clap` to get typed values (i.e. `i32`, `u8`, etc.) from positional or option arguments so long as the type you request implements `std::str::FromStr` See the `examples/12_TypedValues.rs`. You can also use `clap`s `simple_enum!` or `arg_enum!` macro to create an enum with variants that automatically implements `std::str::FromStr`. See `examples/13a_EnumValuesAutomatic.rs` for details.
56
+
//! * **Typed Values**: You can use several convenience macros provided by `clap` to get typed values (i.e. `i32`, `u8`, etc.) from positional or option arguments so long as the type you request implements `std::str::FromStr` See the `examples/12_TypedValues.rs`. You can also use `clap`s `simple_enum!` or `arg_enum!` macro to create an enum with variants that automatically implements `std::str::FromStr`. See `examples/13a_EnumValuesAutomatic.rs` for details and performs an ascii case insensitive parse from a `string`->`enum`.
57
+
//! * **Suggestions**: Suggests corrections when the user enter's a typo. For example, if you defined a `--myoption <value>` argument, and the user mistakenly typed `--moyption value` (notice `y` and `o` switched), they would receive a `Did you mean '--myoption' ?` error and exit gracefully. This also works for subcommands and flags. (Thanks to [Byron](https://github.com/Byron) for the implementation) (This feature can optionally be disabled, see 'Optional Dependencies / Features')
58
+
//! * **Colorized (Red) Errors**: Error message are printed in red text (this feature can optionally be disabled, see 'Optional Dependencies / Features').
56
59
//!
57
60
//! ## Quick Example
58
61
//!
59
-
//! The following two examples show a quick example of some of the very basic functionality of `clap`. For more advanced usage, such as requirements, exclusions, groups, multiple values and occurrences see the [video tutorials](https://www.youtube.com/playlist?list=PLza5oFLQGTl0Bc_EU_pBNcX-rhVqDTRxv), [documentation](http://kbknapp.github.io/clap-rs/docs/clap/index.html), or `examples/` directory of this repository.
62
+
//! The following two examples show a quick example of some of the very basic functionality of `clap`. For more advanced usage, such as requirements, exclusions, groups, multiple values and occurrences see the [video tutorials](https://www.youtube.com/playlist?list=PLza5oFLQGTl0Bc_EU_pBNcX-rhVqDTRxv), [documentation](http://kbknapp.github.io/clap-rs/clap/index.html), or `examples/` directory of this repository.
60
63
//!
61
64
//! *NOTE:* Both examples are functionally the same, but show two different styles in which to use `clap`
62
65
//!
@@ -270,9 +273,35 @@
270
273
//!
271
274
//! Then run `cargo build` or `cargo update && cargo build` for your project.
272
275
//!
276
+
//! ### Optional Dependencies / Features
277
+
//!
278
+
//! If you'd like to keep your dependency list to **only** `clap`, you can disable any features that require an additional dependency. To do this, add this to your `Cargo.toml`:
279
+
//!
280
+
//! ```ignore
281
+
//! [dependencies.clap]
282
+
//! version = "*"
283
+
//! default-features = false
284
+
//! ```
285
+
//!
286
+
//! You can also selectively enable only the features you'd like to include, by adding:
287
+
//!
288
+
//! ```ignore
289
+
//! [dependencies.clap]
290
+
//! version = "*"
291
+
//! default-features = false
292
+
//!
293
+
//! # Cherry-pick the features you'd like to use
294
+
//! features = [ "suggestions", "color" ]
295
+
//! ```
296
+
//!
297
+
//! The following is a list of optional `clap` features:
298
+
//!
299
+
//! * **"suggestions"**: Turns on the `Did you mean '--myoption' ?` feature for when users make typos.
300
+
//! * **"color"**: Turns on red error messages.
301
+
//!
273
302
//! ### More Information
274
303
//!
275
-
//! You can find complete documentation on the [github-pages site](http://kbknapp.github.io/clap-rs/docs/clap/index.html) for this project.
304
+
//! You can find complete documentation on the [github-pages site](http://kbknapp.github.io/clap-rs/clap/index.html) for this project.
276
305
//!
277
306
//! You can also find usage examples in the `examples/` directory of this repo.
278
307
//!
@@ -300,11 +329,10 @@
300
329
//!
301
330
//! ### Running the tests
302
331
//!
303
-
//! If contributing, you can run the tests as follows (assuming you've cloned the repo to `clap-rs/`
332
+
//! If contributing, you can run the tests as follows (assuming you're in the `clap-rs/` directory)
0 commit comments