$ show google/argh
Argh is an opinionated derive-based argument parsing library for Rust, optimized for code size and conformance to Fuchsia CLI specifications. The repository is a multi-crate workspace: `argh` (public API, re-exports derive macros and provides runtime functions like `from_env`), `argh_derive` (proc-macro implementation of `FromArgs`, `FromArgValue`, and `ArgsInfo`), `argh_shared` (shared data structures for command metadata, used by both derive and completion crates), and `argh_complete` (generators for bash, zsh, fish, and nushell shell completions). The core architecture uses a derive macro to generate parsing code at compile time, producing minimal binary size. It supports switches, options (required, optional, repeating), positional arguments (including greedy/remainder), subcommands (static and dynamic), custom parsers via `FromArgValue`, default values, and extensive help/usage formatting with notes, examples, and error codes. The library is well-tested with unit tests, compile-fail UI tests, and integration tests. It is designed as a lightweight alternative to clap, prioritizing code size and compile-time speed.
The LLM identified 3 files worth highlighting for reuse:
Defines the core data structures for command metadata (CommandInfo, CommandInfoWithArgs, FlagInfo, etc.) and provides a reusable `write_description` function that formats command names and descriptions with word wrapping and indentation. This module has zero internal dependencies (only optional serde) and can be extracted as a standalone formatting utility for any CLI framework.
A self-contained generator for Bash shell completions that takes a `CommandInfoWithArgs` structure and produces a complete Bash completion function with recursive subcommand handling. It demonstrates a clean pattern for generating shell completion scripts from structured metadata and could be reused for other argument parsers or CLI tools.
Implements an error accumulation and reporting pattern for procedural macros. Uses a `RefCell` to collect multiple `syn::Error` instances and emit them all at compile time, enabling detailed validation with multiple error messages. This pattern is reusable in any proc-macro crate that needs to validate input and report multiple errors.