- Home
- Skills
- Zhanghandong
- Rust Skills
- Domain Cli
domain-cli_skill
- Shell
565
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill zhanghandong/rust-skills --skill domain-cli- SKILL.md3.9 KB
Overview
This skill provides practical guidelines and patterns for building robust Rust CLI tools. It captures domain constraints (user communication, config precedence, exit codes, interrupt handling) and maps them to concrete crates and code patterns for argument parsing, config layering, progress display, and terminal UI. Use it to design predictable, scriptable, and user-friendly command-line applications.
How this skill works
The skill inspects common CLI domain rules and translates them into design constraints and Rust implementations. It recommends crates (clap, figment/config, indicatif, dialoguer, ratatui, crossterm) and patterns (derive-based args structs, subcommands, layered config, RAII progress bars). It also enumerates common mistakes and the fixes to enforce correct stdout/stderr usage, exit codes, and config precedence.
When to use it
- Building a new Rust command-line tool or utility
- Designing argument parsing and subcommands with type safety
- Implementing layered configuration (CLI > env > file > defaults)
- Adding progress indicators, prompts, or TUI components
- Ensuring correct exit codes and scriptable output
Best practices
- Send data to stdout and errors to stderr (println! vs eprintln!)
- Enforce config precedence: CLI args > environment vars > config file > defaults
- Use #[derive(Parser)] and #[derive(Subcommand)] from clap for type-driven args
- Return Result from main or call std::process::exit with non-zero codes on error
- Use RAII-style progress bars (indicatif) for long operations and signal handling for interrupts
Example use cases
- A scaffolding tool with Init and Run subcommands parsed via clap derives
- A background worker that reads config from file, environment, and CLI with clear precedence
- An installer that shows progress bars and interactive prompts (indicatif + dialoguer)
- A TUI-based admin tool using ratatui + crossterm with proper terminal cleanup
- A CLI intended for automation where stdout is machine-readable and stderr contains human messages
FAQ
Define a top-level args struct with #[derive(Parser)] and an enum with #[derive(Subcommand)] for subcommands; match the enum to dispatch handlers.
What is the recommended config precedence?
Apply sources in order: CLI args override environment variables, which override config file values, which override built-in defaults.