Skip to main content

Rust CLI Tool with Clap & Error Handling

Build a production Rust CLI with clap parsing, custom errors, colored output, progress bars, async I/O, config, tests, and CI release.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Build a Rust CLI tool that monitors and manages Docker containers (list, logs, restart, stats). Include: 1) Argument parsing with clap (derive API) — subcommands: list, logs, restart, stats, watch, 2) Custom error type using thiserror + anyhow with context propagation, 3) Colored terminal output using colored, 4) Progress bar for long operations using indicatif, 5) Configuration file support (TOML) with fallback defaults, 6) Logging with tracing crate (configurable verbosity with -v flags), 7) Async runtime with tokio for I/O operations, 8) Graceful Ctrl+C handling with tokio signal, 9) Unit tests and integration tests with assert_cmd, 10) Cross-platform build configuration (Linux, macOS, Windows). Include Cargo.toml, README with usage examples, and GitHub Actions release workflow.

What this prompt does

This prompt generates a production-grade Rust CLI tool scaffold around a stated purpose rather than a bare argument parser. You set [tool_purpose] and [subcommands], and the AI builds the full structure: clap derive-API argument parsing, a custom error type from [error_lib] with context propagation, colored output via [color_lib], indicatif progress bars for long operations, configuration support in [config_format] with fallback defaults, tracing-based logging with configurable verbosity, and an [async_runtime] for I/O. It produces the parts that make a CLI pleasant to actually use, which is exactly where most hand-rolled tools fall short.

The variables target the parts that genuinely vary between tools. [error_lib] decides your error-handling layer, with thiserror plus anyhow giving typed errors where you need them and easy context at the top, while [color_lib] and [config_format] set the UX and config surface, and [async_runtime] covers any I/O-bound work. The prompt also asks for graceful Ctrl+C handling via tokio signal, unit and integration tests with assert_cmd, cross-platform build configuration, a Cargo.toml, a README with usage examples, and a GitHub Actions release workflow so binaries ship without manual fuss.

When to use it

  • Scaffolding internal tooling or infrastructure CLIs in Rust from a clean base
  • Standing up a tool with proper error context instead of a scatter of bare unwraps
  • Adding progress bars and colored output to a long-running command
  • Wiring config-file plus sensible-defaults support into a new CLI
  • Setting up cross-platform release builds via GitHub Actions from day one
  • Generating integration tests with assert_cmd alongside the implementation itself

Example output

You get a complete project skeleton: a Cargo.toml with the right dependencies, a main module wiring [subcommands] to handlers, a custom error type, colored and progress-bar output, config loading with defaults, tracing setup, and graceful shutdown. Alongside the code you get a README with usage examples, unit and integration tests, and a GitHub Actions workflow that builds release binaries for Linux, macOS, and Windows so cross-platform distribution is handled.

Pro tips

  • Make [tool_purpose] and [subcommands] specific; vague purposes produce vague, generic handlers you will rewrite anyway
  • Keep [error_lib] as thiserror plus anyhow unless you have a reason; it is the idiomatic pairing for libraries plus binaries
  • Match [config_format] to your ecosystem; TOML fits Cargo-native projects naturally and reads cleanly
  • Only request [async_runtime] if the tool does real I/O; a synchronous CLI does not need tokio and runs simpler
  • Build the GitHub Actions release workflow early so cross-platform binaries are never a last-minute scramble
  • Wire the tracing verbosity flags so users can run with -v for normal output and -vv when they need to debug a failure
  • Treat the generated code as a strong scaffold and review the error-context chains before you ship it to anyone

Frequently Asked Questions

Why does the prompt pair thiserror and anyhow instead of just one?
thiserror defines structured, typed errors for library-style code, while anyhow adds easy context propagation for the binary layer. The pairing in `[error_lib]` gives you precise error types where you need them and ergonomic error handling at the top level of the tool.
Do I need the async runtime for every CLI?
No. Only set `[async_runtime]` to tokio if the tool performs real I/O like network calls or concurrent file work. A purely synchronous CLI runs simpler and faster without an async runtime, so leave it out when it adds nothing meaningful.
Will the generated GitHub Actions workflow actually produce cross-platform binaries?
It generates a release workflow targeting Linux, macOS, and Windows, which is a solid starting point. You should still verify it against your repository's settings and run a real release, since CI specifics like caching, signing, and secrets vary by project.
Is the output ready to ship as-is?
Treat it as a strong scaffold, not finished software. The structure, dependencies, and tests are sound, but review the error-context chains, config defaults, and subcommand logic for your exact use case before shipping it to real users.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Rust & Go Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support