Tap – a CLI parsing library for Rust
[]
= "0.1.0"
Tap is a lightweight library for building CLIs in Rust. It provides a simple API for argument parsing, commands, flags, and colored output, with no external dependencies or complex macros.
Features
- Colored output via short codes:
[?GN],[?RD],[?YW], etc. - Auto‑generated help with commands grouped by identical handlers.
- Subcommands (nested commands).
- Zero dependencies (only
std).
Quick Start
Let's create a simple CLI with a hello command:
use ;
Run:
)
Commands and Arguments
Add a command using Engine::new_command:
engine.new_command;
Help will show:
╭─────── Command [copy]
⎬─ Args: <src>, <dst>, [force]
⎬─ Docs:
│ Copy source to destination
╰───────
Flags
Flags are written as --flag, --key=value, or --key:value. They are parsed automatically and stored in ArgsP:
args_p.flags– list of flags without values.args_p.values– dictionary of key → value.
In your handler you can read them:
Colors
Tap supports colored output via short codes like [?COLOR]. Examples:
[?GN],[?GREEN]– green[?BGN],[?BGREEN]– bright green[?BACKGREEN],[?BKGN]– green background[?BACKBGREEN],[?BKBGN]– bright green background[?BOLD],[?BD]– bold[?UNDERLINE],[?UE]– underlined[?RT]– reset
Format – [?<BACKGROUND><BRIGHT><COLOR>], where:
<BACKGROUND>– to choose a background colour, prependBK(short) orBACK(full name) to the colour.<BRIGHT>– to use the bright version, prependB(short for 'bright').<COLOR>– options:- Two letters: first letter – initial of the colour name, second – final letter.
Example:
GN
- Two letters: first letter – initial of the colour name, second – final letter.
Example:
Colours – black, red, green, yellow, blue, magenta, cyan, and their bright variants. All colours are available for the background. For text, bold and underline styles are available.
Use functions from tap::formatting::print and tap::formatting::color:
use println;
use colorize;
let raw = "[?GN]Success![?RT] File saved as [?YW]config.toml[?RT]";
println;
let colored = colorize
Colours can be disabled globally:
use COLOR_ENABLED;
use Ordering;
COLOR_ENABLED.store;
Grouping Commands in Help
Commands with identical CmdInfo values are automatically grouped into one line as aliases:
engine.new_commands;
Help will display: [help / -h].
MIT – see the LICENSE file for details. 2026, By Pt.