Opinionated preferences for building fast, friendly command-line tools in Rust.
# Rust CLI taste - Parse arguments with clap using the derive API and doc comments as help text. Confidence: 0.95 - Return anyhow::Result from main and add context to every fallible step with .context(). Confidence: 0.90 - Define library error types with thiserror and keep anyhow in the binary only. Confidence: 0.85 - Split the crate into a thin main.rs and a lib.rs that holds the real logic for testing. Confidence: 0.85 - Write normal output to stdout and logs, progress and errors to stderr. Confidence: 0.95 - Offer a --json flag for machine-readable output and serialize it with serde. Confidence: 0.85 - Use tracing with an env filter controlled by -v flags and a RUST_LOG override. Confidence: 0.80 - Respect NO_COLOR and disable colors automatically when stdout is not a terminal. Confidence: 0.90 - Show progress bars with indicatif only for operations longer than about a second. Confidence: 0.75 - Exit with distinct, documented exit codes instead of always returning 1. Confidence: 0.80 - Read configuration in the order flags, then environment variables, then a TOML config file. Confidence: 0.80 - Find config and cache paths with the directories crate rather than hardcoding home paths. Confidence: 0.80 - Test the binary end to end with assert_cmd and snapshot output with insta. Confidence: 0.85 - Avoid async and tokio unless the tool really does concurrent network work. Confidence: 0.75 - Generate shell completions and a man page with clap_complete and clap_mangen at build time. Confidence: 0.75 - Ship prebuilt binaries for Linux, macOS and Windows with cargo-dist from GitHub Actions. Confidence: 0.80 - Run cargo clippy with warnings denied and cargo fmt --check in CI. Confidence: 0.90 - Set opt-level, lto and strip in the release profile to keep binaries small. Confidence: 0.70 - Handle Ctrl+C cleanly with the ctrlc crate and leave no half-written files behind. Confidence: 0.80
Opinionated conventions for writing safe, readable and maintainable Bash scripts.
# Shell scripting taste of a DevOps engineer
- Start every script with #!/usr/bin/env bash and set -euo pipefail. Confidence: 0.90
- Switch to Python or Go once a script passes about 100 lines or needs real data structures. Confidence: 0.85
- Run ShellCheck in CI and fix warnings instead of silencing them. Confidence: 0.95
- Format scripts with shfmt so diffs stay small. Confidence: 0.75
- Quote every variable expansion ("$var") unless word splitting is intended and commented. Confidence: 0.95
- Use [[ ]] for tests and $(...) for command substitution, never backticks. Confidence: 0.90
- Declare variables inside functions with local. Confidence: 0.85
- Put the logic in functions and call a main "$@" at the bottom of the file. Confidence: 0.80
- Clean up temporary files with mktemp and trap '...' EXIT. Confidence: 0.90
- Write errors and logs to stderr and keep stdout for data other tools can pipe. Confidence: 0.85
- Exit with a non-zero status and a clear message when something fails. Confidence: 0.90
- Provide a usage function and handle -h and --help. Confidence: 0.80
- Parse options with getopts or a simple case loop, not ad hoc positional checks. Confidence: 0.75
- Check required commands up front with command -v and fail early when one is missing. Confidence: 0.85
- Read configuration from environment variables with defaults, such as -8080. Confidence: 0.80
- Never parse ls output; use globs or find -print0 with xargs -0. Confidence: 0.90
- Read files line by line with while IFS= read -r line. Confidence: 0.85
- Use arrays for argument lists instead of building command strings. Confidence: 0.85
- Avoid eval, and never pass untrusted input to it. Confidence: 0.95
- Make scripts idempotent so running them twice is safe. Confidence: 0.85
- Add a --dry-run flag to anything that deletes or changes remote state. Confidence: 0.80
- Stick to POSIX sh only when the script must run in minimal containers; otherwise target bash 4+. Confidence: 0.70