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.
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'.
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.
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 install claptrap --locked
add-apt-repository ppa:fujiapple/claptrap
apt update && apt install claptrap
ⓘ Note:
Only available for Ubuntu 24.04 (
Noble
) and 22.04 (Jammy
).
snap install claptrap
brew tap fujiapple852/claptrap && brew install claptrap
docker run -it fujiapple/claptrap
See the installation guide for details of how to install Claptrap on your system.
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.
Claptrap is distributed under the terms of the Apache License (Version 2.0).
See LICENSE for details.
Copyright 2025