Coder Social home page Coder Social logo

cmallocfree / clap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clap-rs/clap

0.0 1.0 0.0 13.4 MB

A full featured, fast Command Line Argument Parser for Rust

Home Page: docs.rs/clap

License: Apache License 2.0

Rust 99.88% Makefile 0.06% Python 0.06%

clap's Introduction

clap

Command Line Argument Parser for Rust

Crates.io Crates.io License License Build Status Coverage Status Contributors

Dual-licensed under Apache 2.0 or MIT.

  1. About
  2. Tutorial: Builder API, Derive API
  3. Examples
  4. API Reference
  5. CHANGELOG
  6. FAQ
  7. Questions & Discussions
  8. Contributing
  9. Sponsors

About

Create your command-line parser, with all of the bells and whistles, declaratively or procedurally.

Example

This uses our Derive API which provides access to the Builder API as attributes on a struct:

use clap::Parser;

/// Simple program to greet a person
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
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.10", 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

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 a clap 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.

Sponsors

Gold

Silver

Bronze

Backer

clap's People

Contributors

kbknapp avatar epage avatar pksunkara avatar bors[bot] avatar homu avatar creepyskeleton avatar ldm0 avatar vinatorul avatar texitoi avatar willmurphyscode avatar little-dude avatar nickhackman avatar williamyaoh avatar tormol avatar dylan-dpc avatar rami3l avatar sru avatar gingerdevilish avatar mgeisler avatar mkantor avatar nabijaczleweli avatar fishface60 avatar modprog avatar byron avatar cstyles avatar lu-zero avatar tshepang avatar savish avatar hgrecco avatar pickfire avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.