2020-03-02 09:52:15 +01:00
// Copyright ⓒ 2015-2016 Kevin B. Knapp and [`clap-rs` contributors](https://github.com/clap-rs/clap/graphs/contributors).
2016-01-31 08:03:09 -05:00
// Licensed under the MIT license
// (see LICENSE or <http://opensource.org/licenses/MIT>) All files in the project carrying such
// notice may not be copied, modified, or distributed except according to those terms.
2022-07-19 13:29:31 -05:00
//! > **Command Line Argument Parser for Rust**
//!
//! Quick Links:
//! - Derive [tutorial][_derive::_tutorial] and [reference][_derive]
//! - Builder [tutorial][_tutorial] and [reference](index.html)
//! - [Cookbook][_cookbook]
//! - [FAQ][_faq]
//! - [Discussions](https://github.com/clap-rs/clap/discussions)
//!
//! ## Aspirations
//!
//! - Out of the box, users get a polished CLI experience
//! - Including common argument behavior, help generation, suggested fixes for users, colored output, [shell completions](https://github.com/clap-rs/clap/tree/master/clap_complete), etc
//! - Flexible enough to port your existing CLI interface
//! - However, we won't necessarily streamline support for each use case
//! - Reasonable parse performance
//! - Resilient maintainership, including
//! - Willing to break compatibility rather than batching up breaking changes in large releases
//! - Leverage feature flags to keep to one active branch
//! - Being under [WG-CLI](https://github.com/rust-cli/team/) to increase the bus factor
//! - We follow semver and will wait about 6-9 months between major breaking changes
//! - We will support the last two minor Rust releases (MSRV, currently 1.56.1)
//!
//! While these aspirations can be at odds with fast build times and low binary
//! size, we will still strive to keep these reasonable for the flexibility you
//! get. Check out the
//! [argparse-benchmarks](https://github.com/rust-cli/argparse-benchmarks-rs) for
//! CLI parsers optimized for other use cases.
//!
//! ## Example
//!
//! Run
//! ```console
2022-07-19 22:32:42 +02:00
//! $ cargo add clap --features derive
2022-07-19 13:29:31 -05:00
//! ```
//! *(See also [feature flag reference][_features])*
//!
2022-07-19 15:54:01 -05:00
//! Then define your CLI in `main.rs`:
2022-07-19 13:29:31 -05:00
#![ cfg_attr(not(feature = " derive " ), doc = " ```ignore " ) ]
#![ cfg_attr(feature = " derive " , doc = " ```no_run " ) ]
#![ doc = include_str!( " ../examples/demo.rs " ) ]
//! ```
//!
2022-07-19 15:54:01 -05:00
//! And try it out:
2022-07-19 13:29:31 -05:00
#![ doc = include_str!( " ../examples/demo.md " ) ]
//!
//! See also the derive [tutorial][_derive::_tutorial] and [reference][_derive]
//!
//! ### Related Projects
//!
//! Augment clap:
//! - [wild](https://crates.io/crates/wild) for supporting wildcards (`*`) on Windows like you do Linux
//! - [argfile](https://crates.io/crates/argfile) for loading additional arguments from a file (aka response files)
//! - [shadow-rs](https://crates.io/crates/shadow-rs) for generating `Command::long_version`
//! - [clap_mangen](https://crates.io/crates/clap_mangen) for generating man page source (roff)
//! - [clap_complete](https://crates.io/crates/clap_complete) for shell completion support
//!
//! CLI Helpers
//! - [clap-verbosity-flag](https://crates.io/crates/clap-verbosity-flag)
//! - [clap-cargo](https://crates.io/crates/clap-cargo)
//! - [concolor-clap](https://crates.io/crates/concolor-clap)
//!
//! Testing
//! - [`trycmd`](https://crates.io/crates/trycmd): Bulk snapshot testing
//! - [`snapbox`](https://crates.io/crates/snapbox): Specialized snapshot testing
//! - [`assert_cmd`](https://crates.io/crates/assert_cmd) and [`assert_fs`](https://crates.io/crates/assert_fs): Customized testing
//!
//! Documentation:
//! - [Command-line Apps for Rust](https://rust-cli.github.io/book/index.html) book
//!
2021-12-16 10:36:41 -06:00
#![ cfg_attr(docsrs, feature(doc_auto_cfg)) ]
2021-12-07 16:22:14 -06:00
#![ doc(html_logo_url = " https://raw.githubusercontent.com/clap-rs/clap/master/assets/clap.png " ) ]
2021-12-06 11:03:12 -06:00
#![ warn(
2019-04-05 15:51:22 -04:00
missing_docs ,
missing_debug_implementations ,
missing_copy_implementations ,
trivial_casts ,
unused_allocation ,
2022-01-04 07:20:03 +00:00
trivial_numeric_casts ,
clippy ::single_char_pattern
2019-04-05 15:51:22 -04:00
) ]
2020-08-20 18:38:40 -04:00
#![ forbid(unsafe_code) ]
2021-12-22 09:52:02 -06:00
// HACK https://github.com/rust-lang/rust-clippy/issues/7290
2021-06-17 19:19:56 +01:00
#![ allow(clippy::single_component_path_imports) ]
2021-10-23 10:06:19 -05:00
#![ allow(clippy::branches_sharing_code) ]
2022-01-04 09:00:13 -06:00
// Doesn't allow for debug statements, etc to be unique
#![ allow(clippy::if_same_then_else) ]
2022-07-28 15:11:28 -05:00
// Breaks up parallelism that clarifies intent
#![ allow(clippy::collapsible_else_if) ]
2015-08-19 21:44:25 -04:00
2020-02-02 02:02:10 +01:00
#[ cfg(not(feature = " std " )) ]
2020-03-19 10:17:52 +03:00
compile_error! ( " `std` feature is currently required to build `clap` " ) ;
2020-02-02 02:02:10 +01:00
2022-06-03 12:11:45 -05:00
pub use crate ::builder ::ArgAction ;
2022-05-12 05:03:26 -05:00
pub use crate ::builder ::Command ;
2022-05-12 05:07:54 -05:00
pub use crate ::builder ::{ Arg , ArgGroup } ;
2022-02-02 16:06:23 -06:00
pub use crate ::error ::Error ;
2022-05-12 05:07:54 -05:00
pub use crate ::parser ::ArgMatches ;
2021-10-27 22:01:04 +01:00
#[ cfg(feature = " color " ) ]
pub use crate ::util ::color ::ColorChoice ;
2022-04-22 12:19:43 -05:00
#[ cfg(not(feature = " color " )) ]
#[ allow(unused_imports) ]
pub ( crate ) use crate ::util ::color ::ColorChoice ;
2020-02-14 17:22:01 +01:00
2022-06-08 10:56:57 -05:00
pub use crate ::derive ::{ Args , CommandFactory , FromArgMatches , Parser , Subcommand , ValueEnum } ;
2020-08-11 16:30:02 +02:00
2022-02-11 21:48:29 -06:00
#[ allow(deprecated) ]
2022-07-22 15:50:13 -05:00
pub use crate ::builder ::{ PossibleValue , ValueHint } ;
2022-05-12 05:07:54 -05:00
pub use crate ::error ::{ ErrorKind , Result } ;
2022-05-24 10:16:50 -05:00
#[ allow(deprecated) ]
2022-07-21 13:47:06 -05:00
pub use crate ::parser ::{ Indices , ValueSource } ;
2022-02-11 21:48:29 -06:00
2018-07-13 11:36:53 -04:00
#[ cfg(feature = " derive " ) ]
2020-09-24 13:41:37 +02:00
#[ doc(hidden) ]
2019-12-29 18:53:12 +03:00
pub use clap_derive ::{ self , * } ;
2022-07-19 13:29:31 -05:00
#[ cfg(feature = " unstable-doc " ) ]
pub mod _cookbook ;
#[ cfg(feature = " unstable-doc " ) ]
pub mod _derive ;
#[ cfg(feature = " unstable-doc " ) ]
pub mod _faq ;
#[ cfg(feature = " unstable-doc " ) ]
pub mod _features ;
#[ cfg(feature = " unstable-doc " ) ]
pub mod _tutorial ;
2020-08-21 08:21:21 +03:00
#[ doc(hidden) ]
2022-06-26 00:44:58 +01:00
pub mod __macro_refs {
#[ cfg(any(feature = " derive " , feature = " cargo " )) ]
#[ doc(hidden) ]
pub use once_cell ;
}
2018-07-13 11:36:53 -04:00
2015-04-10 11:40:08 -04:00
#[ macro_use ]
2020-01-01 23:27:44 +05:30
#[ allow(missing_docs) ]
2020-05-15 09:51:36 +02:00
mod macros ;
2018-07-26 20:15:47 +05:00
2020-05-15 09:51:36 +02:00
mod derive ;
2020-02-08 22:36:00 +03:00
2022-05-12 05:03:26 -05:00
pub mod builder ;
2022-02-02 16:06:23 -06:00
pub mod error ;
2022-05-12 05:03:26 -05:00
pub mod parser ;
2022-02-02 16:06:23 -06:00
2018-07-19 15:50:47 +03:00
mod mkeymap ;
2018-07-23 15:09:42 -04:00
mod output ;
2018-06-12 11:42:03 -04:00
mod util ;
2016-01-11 03:59:56 -05:00
2018-11-14 12:12:34 -05:00
const INTERNAL_ERROR_MSG : & str = " Fatal internal error. Please consider filing a bug \
2020-02-05 11:04:59 +01:00
report at https ://github.com/clap-rs/clap/issues";
2018-11-14 12:12:34 -05:00
const INVALID_UTF8 : & str = " unexpected invalid UTF-8 code point " ;