Tap - a CLI parsing library for Rust
# OR
Tap is a lightweight library for building CLIs in Rust. Simple API for parsing arguments, commands, flags, and colored output. One dependency (string_template), no macros.
Features
- Colored output via short codes:
[?GN],[?RD],[?YW], etc. - Auto-generated help with grouping of commands by identical handlers.
- Subcommands (nested commands).
- Output renderers with templates and typing plus JSON serialization.
Quick start
A simple CLI with a hello command:
use ;
Run:
)
The box-drawing characters in the help output are what generate_help actually prints. Not a README decoration.
Commands and arguments
engine.new_command;
The help will show:
╭─────── Command [copy]
⎬─ Args: <src>, <dst>, [force]
⎬─ Docs:
│ Copy source to destination
╰───────
Flags
Flags are written as --flag, --key=value, --key:value. They are parsed automatically in ArgsP:
args_p.flags- list of flags without values.args_p.values- dictionary key -> value.
Reading in a handler:
Important: flags are stripped from args before the handler is called. Access them only via e.args_p.
Colors
Colored output via [?COLOR] codes:
[?GN],[?GREEN]- green[?BGN],[?BGREEN]- bright green[?BACKGREEN],[?BKGN]- green background[?BACKBGREEN],[?BKBGN]- bright green background[?BOLD],[?BD]- bold[?DIM],[?DM]- dim[?ITALIC],[?IT]- italic[?UNDERLINE],[?UE]- underline[?BLINK],[?BL]- blinking[?REVERSE],[?RV]- reverse[?STRIKETHROUGH],[?ST]- strikethrough[?RT]- reset
Format: [?<BACKGROUND><BRIGHT><COLOR>].
<BACKGROUND>- prefixBK(short) orBACK(full) for background.<BRIGHT>- prefixBfor the bright variant.<COLOR>- name or two letters (first and last letter of the name). Example:GN= green.
Palette
Standard 16: black, red, green, yellow, blue, magenta, cyan, white, and their bright variants. All are available as background.
Extended (xterm-256): also available as background:
| Name | Abbr. | Name | Abbr. |
|---|---|---|---|
| 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
BOLD (BD), DIM/FAINT (DM), ITALIC (IT), UNDERLINE (UE), BLINK (BL), REVERSE (RV), STRIKETHROUGH (ST), RESET (RT).
Usage
use println;
use colorize;
let raw = "[?GN]Success![?RT] File saved as [?YW]config.toml[?RT]";
println; // prints already colored
let colored: String = colorize; // or get a string
println/print in colors::print already call colorize internally - no need to colorize twice.
Disable colors globally:
use COLOR_ENABLED;
use Ordering;
COLOR_ENABLED.store;
Unknown codes ([?FOO]) are not consumed or turned into garbage - they remain in the string as-is. This is convenient for debugging.
Grouping commands in help
Commands with identical CmdInfo are automatically grouped into one line as aliases:
engine.new_commands;
The help will show [help / -h].
required, optional, unlimited, and docs are compared. If docs differ, there will be no grouping.
Renderers
The tooling::renderable module allows templating output by scope:
use ;
let mut r = new;
r.scope.insert;
r.scope.insert; // :int - validated as a number
r.scope.insert; // :bool - only "true"/"false"
add_template_render;
add_template_render_colored;
println!;
println!;
println!; // {"name":"Rust","stable":true,"version":1}
render_json returns a Result - for an invalid :int/:bool it returns RenderError::InvalidValue rather than silently inserting garbage into JSON.
MIT - see the LICENSE file for details. 2026, By Pt.