A simple, lightweight and extensible command line argument parser for rust codebases

Overview

A simple, lightweight and extensible command line argument parser for rust codebases.

GitHub Workflow Status Crates.io Crates.io

This crate aims to provide you with an easy-to-use and extensible API without compromising the speed and performance that is expected of rust codebases. The syntax of the builder interface can be attributed to the javascript package commander-js. To get started, create a new instance of the program and manipulate it as shown.

A basic example

The following is a basic example on how to use the crate. More in depth documentation can be found from docs.rs or the github repo.

let mut program = Program::new();

program
    .version("0.1.0")
    .description("An example CLI")
    .author("Author's name");

program
    .subcommand("test")
    .argument("<app-name>", "Pass the name of the app to test")
    .alias("t")
    .description("A test command")
    .option("-s --skip", "Skip checking/installing the dependencies")
    .option("-p --priority", "The priority to use when testing apps")
    .action(|matches| { dbg!(matches); });

// ...

program.parse();

Extending the functionality using event listeners

The default behaviour of the program can be easily extended or even overriden by use of event listeners. View the docs to see all possible events of the program.

//...

program.on(Event::OutputVersion, |config|{
    let prog_ref = config.get_program();
    println!("Current program version is: {}", prog_ref.get_version());
});

program.after_help(|config|{
    let prog_ref = config.get_program();
    println!("This program was authored by: {}", prog_ref.get_author());
});

program.before_all(|config|{
    println!("An Aram Mojtabai banger!!!😂")
});

// ...

Configuring program settings

Modify the settings to control the behavior of the program. See the documentation for all possible configurable settings

// ...

program.set(Setting::ShowHelpOnAllErrors(true));
program.set(Setting::ChoosePredefinedTheme(PredefinedThemes::Colorful));
program.set(Setting::SetProgramPattern(Pattern::Legacy));
program.set(Setting::OverrideAllDefaultListeners(true));

// ...

Customizing themes and patterns

You can define your own color pallete to be used when printing to std_out. Also, you can control how the information is printed by use of patterns.

// ...

use Color::*;
program.set(Setting::DefineCustomTheme(construct_theme!(
    Green, Magenta, Blue, Red, White
)));


// ...

Refer to docs.rs for full documentation on the crate. Also check out the repository on github for examples of crate usage here. If you found this crate useful, consider starring this repo.

Contributing

Whether you have an awesome color palette to create a new predefined theme, or you wish to add a new use-case to the examples/ directory, or you have a change that can improve the crate, all contributions are welcome and highly appreciated!

You might also like...
Argument parsing for the future 🚀

argi Argument parsing for the future 🚀 Features Macro-based approach, providing an intuitive way to layout a cli Rich auto-help generation, styling b

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 .

A lightweight command line utility with some small functions for CTFs.

Ice Ice is a lightweight command line utility to help with simple problems encountered while playing CTFs. Extracted from graveyard NOTE: Most of the

Lightweight command line tool to quickly navigate across folders.

slingshot 0.3.0 Slingshot is a lightweight tool to browse files in the terminal. It allows the user to quickly filter through files in any directory,

Configurable, extensible, interactive line reader

linefeed linefeed is a configurable, concurrent, extensible, interactive input reader for Unix terminals and Windows console. API Documentation linefe

A fully extensible command interface to navigate around your leptos application.

leptos-kbar A fully extensible command interface to navigate around your leptos application. See demo: https://leptos-kbar.vercel.app/ Roadmap leptos-

Simple, extensible multithreaded background job processing library for Rust.
Simple, extensible multithreaded background job processing library for Rust.

Apalis Apalis is a simple, extensible multithreaded background job processing library for Rust. Features Simple and predictable job handling model. Jo

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

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

Releases(v0.6.1)
Owner
Victor Ndaba
I have a strong liking for JavaScript, Rust and blender, the open source 3d software❤❤.
Victor Ndaba
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 minimal argument parser

Pieces An argument parser built with control in mind. Parsing The results you get are dependent on what order you parse in. If you want to say only pa

ibx34 3 Sep 30, 2021
Design token framework — adopt a unified design language across platforms, codebases, and teams

Palette Design tokens framework with atomic classes for React and Master CSS. Deliver a consistent visual identity across your apps with design tokens

Foretag 4 Aug 23, 2022
argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper with a

argmax argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper w

David Peter 22 Nov 20, 2022
Simple command line flag parser for rust.

easy_flag Simple command line flag parser for rust. use easy_flag::FlagSet; fn main() -> Result<(), String>{ let mut help = false; let mut my

BillyfBrain 3 Oct 20, 2021
Lightweight alternative Discord client with a smaller footprint and some fancy extensible features.

Dorion Dorion is an alternative Discord client aimed and lower-spec or storage-sensitive PCs that supports themes, plugins, and more! Table of Content

SpikeHD 20 Jan 2, 2023
Dreamer is an extensible tool manager and shell for creating small, lightweight, dev environments instantly.

Dreamer ?? Does what you want, not what you say. Dreamer is a universal tool management system for any language, any build system, and any framework.

Luke Davis 4 Oct 23, 2023
Rust derive-based argument parsing optimized for code size

Argh Argh is an opinionated Derive-based argument parser optimized for code size Derive-based argument parsing optimized for code size and conformance

Google 1.3k Dec 28, 2022