Crate claptrap

Source
Expand description

ci Documentation Crate

§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 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 on Linux, macOS, Windows and BSD.

Claptrap can also generate shell completions, man pages, markdown documentation and template scripts.

See the documentation for more details.

§Installation

§Cargo

Crates.io

cargo install claptrap --locked

§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

Structs§

Command
A deserializable representation of a Clap command.

Enums§

ValueParser