Tap - a CLI parsing library for Rust
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[?DIM],[?DM]- dim / faint[?ITALIC],[?IT]- italic[?UNDERLINE],[?UE]- underlined[?BLINK],[?BL]- blinking[?REVERSE],[?RV]- reverse video[?STRIKETHROUGH],[?ST]- strikethrough[?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
Standard 16 - black, red, green, yellow, blue, magenta, cyan, white, and their bright variants. All colours are available for the background.
Extended (xterm-256) - additional named colours available for both foreground and background:
| Name | Short | Name | Short |
|---|---|---|---|
| orange | OE |
lime | LE |
| pink | PK |
teal | TL |
| purple | PE |
navy | NY |
| violet | VT |
gold | GD |
| brown | BN |
silver | SR |
| gray | GY |
maroon | MN |
Examples: [?OE] - orange, [?BACKGOLD] / [?BKGD] - gold background, [?BKOE] - orange background.
Styles
For text, the following styles are available: BOLD (BD), DIM/FAINT (DM), ITALIC (IT), UNDERLINE (UE), BLINK (BL), REVERSE (RV), STRIKETHROUGH (ST), and RESET (RT).
Usage
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.