Simple command line flag parser for rust.

Overview

easy_flag

Simple command line flag parser for rust.

use easy_flag::FlagSet;

fn main() -> Result<(), String>{
    let mut help = false;
    let mut my_flag = String::from("default value");
    let args: Vec<String> = std::env::args().collect();

    let mut my_set = FlagSet::new(&args[0])
        .add("-h, --help", &mut help, "Prints help message.")
        .add("-m, --my-flag", &mut my_flag, "Help message for my_flag with string `value`");

    if let Err(err) = my_set.parse(&args[1..]) {
        println!("{}", my_set.defaults());
        return Err(err);
    }

    let usage = my_set.usage();
    if help {
        println!("{}", usage);
        return Ok(());
    }

    println!("my_flag flag value: {}", my_flag);

    Ok(())
}

License

Licensed under either of Apache License, Version2.0 or MIT license at your option.
You might also like...
A simple command-line calculator program writen with Rust.

Calculator.rs An simple command-line calculator program writen with Rust. Features Math functions support sin(1) = 0.84147098 Variable support a

Cork is a simple command-line calculator, mainly targeted towards people who deal with hex numbers
Cork is a simple command-line calculator, mainly targeted towards people who deal with hex numbers

Cork is a simple command-line calculator, mainly targeted towards people who deal with hex numbers. It deals only with integer arithmetic. Expressions may involve mixed bases (limited to decimal, hexadecimal, octal and binary numbers). The global output format may be set to a particular radix - by default it is hex.

A dead simple functional testing tool for command line applications

Pharaoh : build that test pyramid! What it is Pharaoh is a dead simple, no permission needed, functional test runner for command line applications, wr

A simple command line tool for creating font palettes for engines like libtcod

palscii A simple command line tool for creating font palettes for engines like libtcod. Usage This can also be viewed by running palscii --help. palsc

A simple command line based RPN calculator

stak A simple command line based RPN calculator Usage stak can be used in two modes: one-shot from the command line, or in an interactive shell One-sh

Brutally simple command line app for jotting things down

jot Brutally simple command line app for jotting things down. About jot lets you get things down before you forget, without fiddling folders, naming,

A simple command line program to upload file or directory to web3.storage with optional encryption and compression
A simple command line program to upload file or directory to web3.storage with optional encryption and compression

w3s-cli A simple command line program to upload file or directory to web3.storage with optional encryption and compression. Features Uploads single fi

☘️ A simple command line tool to manage your Minecraft Bedrock worlds
☘️ A simple command line tool to manage your Minecraft Bedrock worlds

☘️ Haze A simple command line tool to manage your Minecraft Bedrock worlds Haze allows you to keep your project's worlds out of the com.mojang directo

An attribute macro to simplify writing simple command line applications.

fncli An attribute macro to simplify writing simple command line applications. Example #[fncli::cli] fn main(a: i32, b: i32) { println!("{}", a +

A CLI-based pride flag generator written in Rust

?? prideful (in development) A CLI-based pride flag generator written in Rust. How to run Build the project using cargo. Install cargo by following th

Angelo-F 35 Sep 3, 2022
A simple, lightweight and extensible command line argument parser for rust codebases

A simple, lightweight and extensible command line argument parser for rust codebases. This crate aims to provide you with an easy-to-use and extensibl

Victor Ndaba 20 Nov 12, 2022
Small command-line tool to switch monitor inputs from command line

swmon Small command-line tool to switch monitor inputs from command line Installation git clone https://github.com/cr1901/swmon cargo install --path .

William D. Jones 5 Aug 20, 2022
A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

null 10.4k Jan 10, 2023
Docopt for Rust (command line argument parser).

THIS CRATE IS UNMAINTAINED This crate is unlikely to see significant future evolution. The primary reason to choose this crate for a new project is if

null 743 Jan 1, 2023
A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

Ed Page 0 Jun 16, 2022
A language parser tool to build recursive descent top down parser.

lang-pt A language parser tool to generate recursive descent top down parser. Overview Parsers written for the languages like Javascript are often cus

Creative Forest 7 Jan 4, 2023
Command-line HTTP client for sending a POST request to specified URI on each stdin line.

line2httppost Simple tool to read lines from stdin and post each line as separate POST request to a specified URL (TCP connection is reused though). G

Vitaly Shukela 3 Jan 3, 2023
Pink is a command-line tool inspired by the Unix man command.

Pink is a command-line tool inspired by the Unix man command. It displays custom-formatted text pages in the terminal using a subset of HTML-like tags.

null 3 Nov 2, 2023
This is a simple command line application to convert bibtex to json written in Rust and Python

bibtex-to-json This is a simple command line application to convert bibtex to json written in Rust and Python. Why? To enable you to convert very big

null 3 Mar 23, 2022