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 supports the full range of Clap features, including short and long flags, default values, subcommands, argument groups, typed parsing, value hints, environment variables, color and styles and many more. See the full list of supported Clap features.
Command line interface specifications can be declared in toml
, yaml
or json
and reused across bash
and zsh
scripts.
Claptrap can also generate shell completions, man pages, markdown documentation and template scripts.
See the documentation for more details.
Claptrap runs on Linux, BSD, macOS, and Windows. It can be installed from most 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