4 releases (breaking)
| 0.3.0 | Aug 16, 2025 |
|---|---|
| 0.2.0 | Jul 20, 2025 |
| 0.1.0 | Jul 18, 2025 |
| 0.0.0 | Jun 11, 2025 |
#1904 in Command line utilities
258 downloads per month
1.5MB
3.5K
SLoC
Claptrap ððŠĪ
Bring the power of Clap to shell scripts.
Claptrap is a tool that allows you to parse complex command line arguments in shell scripts using a declarative specification.
Example
hello.sh:
#!/usr/bin/env bash
set -euo pipefail
eval "$(claptrap --spec - -- "$@" <<'SPEC'
name = "hello"
[args]
name = { short = 'n', long = "name", default-value = "world" }
SPEC
)"
echo "hello, ${claptrap_name}!"
Show usage:
$ ./hello.sh -h
Usage: hello [OPTIONS]
Options:
-n, --name <name> [default: world]
-h, --help Print help
Parse arguments:
$ ./hello.sh -n fuji
hello, fuji!
Error handling:
$ ./hello.sh --nam fuji
./hello.sh --nam fuji
error: unexpected argument '--nam' found
tip: a similar argument exists: '--name'
Usage: hello --name <name>
For more information, try '--help'.
Features
Claptrap brings the full power of Clap command line parsing to shell scripts. Command line interface specifications can
be declared in toml, yaml or json and used as standalone files or embedded directly in scripts.
Claptrap Supports bash, zsh, fish and PowerShell scripts and can run on Linux, BSD, macOS, and Windows. Claptrap
can also automatically generate shell completions, man pages, markdown documentation and template scripts.
See the documentation for more details.
Install
Claptrap can be installed from many package managers, precompiled binaries, or source.
For example, to install Claptrap from cargo:
cargo install claptrap --locked
All package managers
Cargo
cargo install claptrap --locked
PPA (Ubuntu)
add-apt-repository ppa:fujiapple/claptrap
apt update && apt install claptrap
â Note:
Only available for Ubuntu 24.04 (
Noble) and 22.04 (Jammy).
Snap (Linux)
snap install claptrap
Homebrew (macOS)
brew tap fujiapple852/claptrap && brew install claptrap
Docker
docker run -it fujiapple/claptrap
All Repositories
See the installation guide for details of how to install Claptrap on your system.
Goals and non-goals
Claptrap is a command line tool that wraps the clap library and provides integration with shell scripts. The goal is
to expose the full power of Clap to shell scripts, allowing you to define your command line interface in a declarative
way.
If you prefer to parse command line arguments using native shell scripts then you should consider using an alternative tools. Adding support for generating shell scripts that parse command line arguments is a non-goal for Claptrap.
Alternatives
License
Claptrap is distributed under the terms of the Apache License (Version 2.0).
See LICENSE for details.
Copyright 2025
Dependencies
~9â24MB
~329K SLoC