Bring the power of clap
command line parsing to shell scripts.
myapp.sh
:
#!/usr/bin/env bash
set -euo pipefail
eval "$(claptrap --spec myapp.toml -- "$@")"
echo "mode: $claptrap_mode"
echo "protocol: $claptrap_protocol"
myapp.toml
:
name = "myapp"
version = "0.1.0"
[args]
mode = { short = "m", long = "mode" }
protocol = { short = "p", long = "protocol" }
Show usage (also -h
or --help
):
$ ./myapp.sh
Usage: myapp [OPTIONS]
Options:
-m, --mode <mode>
-p, --protocol <protocol>
-h, --help Print help
-V, --version Print version
Show version:
$ ./myapp.sh -V
myapp 0.1.0
Parse arguments:
$ ./myapp.sh -m normal --protocol http
mode: normal
protocol: http
Error handling:
$ ./myapp.sh -m normal --protocl http
error: unexpected argument '--protocl' found
tip: a similar argument exists: '--protocol'
Usage: myapp --mode <mode> --protocol <protocol>
For more information, try '--help'.
To run Claptrap from a Docker container, you can use the following command. Make sure to mount the directory where the application specification file is located in the container.
docker run -it -v ${PWD}:/spec fujiapple/claptrap --spec /spec/myapp.toml
cargo install claptrap --locked
Incomplete WIP, unpublished, experimental.
Claptrap is distributed under the terms of the Apache License (Version 2.0).
See LICENSE for details.
Copyright 2025