mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
No description
88a335ff97
`clap_generate` originally intended to be "generate anything". With `fig`, we already broke one part out. With #3174's man support, we are also looking at keeping it separate: - More freedom to iterate on the API - Uniqueness (and potential weight) of its dependencies - man generation is normally more for distribution while completions are a mix of being distributed with the app or the app generating the completions (which will be exacerbated if we move most completion parsing logic to be in Rust) So `clap_generate` is having a lot more limited of a role than the original name conveys. I worry the generic name will be a hindrance to people discovering and using it (yes, documentation can help but there are limits). I hesitated because we are on the verge of releasing 3.0. However, doing it even later will be even more disruptive because more people will be using it (crates.io lists ~70 people using `clap_generate`). To ease things, we are still releasing `clap_generate` as a wrapper around `clap_complete`. |
||
---|---|---|
.github | ||
assets | ||
benches | ||
clap_complete | ||
clap_complete_fig | ||
clap_derive | ||
clap_generate | ||
clap_generate_fig | ||
docs | ||
examples | ||
src | ||
tests | ||
.clippy.toml | ||
.gitignore | ||
.pre-commit-config.yaml | ||
Cargo.toml | ||
CHANGELOG.md | ||
clap.schema.json | ||
committed.toml | ||
CONTRIBUTING.md | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
Makefile | ||
README.md | ||
release.toml | ||
typos.toml |
clap
Command Line Argument Parser for Rust
Dual-licensed under Apache 2.0 or MIT.
- About
- Tutorial: Builder API, Derive API
- Examples
- API Reference
- CHANGELOG
- FAQ
- Questions & Discussions
- Contributing
- Sponsors
About
Create your command-line parser, with all of the bells and whistles, declaratively or procedurally.
Example
use clap::Parser;
/// Simple program to greet a person
#[derive(Parser, Debug)]
#[clap(about, version, author)]
struct Args {
/// Name of the person to greet
#[clap(short, long)]
name: String,
/// Number of times to greet
#[clap(short, long, default_value_t = 1)]
count: u8,
}
fn main() {
let args = Args::parse();
for _ in 0..args.count {
println!("Hello {}!", args.name)
}
}
Add this to Cargo.toml
:
[dependencies]
clap = { version = "3.0.0-rc.11", features = ["derive"] }
$ demo --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser
USAGE:
demo[EXE] [OPTIONS] --name <NAME>
OPTIONS:
-c, --count <COUNT> Number of times to greet [default: 1]
-h, --help Print help information
-n, --name <NAME> Name of the person to greet
-V, --version Print version information
(version number and .exe
extension on windows replaced by placeholders)
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, 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 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.54.0)
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 for CLI parsers optimized for other use cases.
Related Projects
- wild for supporting wildcards (
*
) on Windows like you do Linux - argfile for loading additional arguments from a file (aka response files)
- clap_complete for shell completion support
- clap-verbosity-flag
- clap-cargo
- concolor-clap
- Command-line Apps for Rust book
trycmd
: Snapshot testing- Or for more control,
assert_cmd
andassert_fs
- Or for more control,
Feature Flags
Default Features
- std: Not Currently Used. Placeholder for supporting
no_std
environments in a backwards compatible manner. - color: Turns on colored error messages.
- suggestions: Turns on the
Did you mean '--myoption'?
feature for when users make typos.
Optional features
- derive: Enables the custom derive (i.e.
#[derive(Parser)]
). Without this you must use one of the other methods of creating aclap
CLI listed above. - cargo: Turns on macros that read values from
CARGO_*
environment variables. - env: Turns on the usage of environment variables during parsing.
- regex: Enables regex validators.
- unicode: Turns on support for unicode characters (including emoji) in arguments and help messages.
- wrap_help: Turns on the help text wrapping feature, based on the terminal size.
Experimental features
Warning: These may contain breaking changes between minor releases.
- unstable-replace: Enable
App::replace
- unstable-multicall: Enable
AppSettings::Multicall
- unstable-grouped: Enable
ArgMatches::grouped_values_of