install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/rust-clap" ~/.claude/skills/comeonoliver-skillshub-rust-clap && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/rust-clap/SKILL.mdsource content
Rust Clap Best Practices
Comprehensive best practices guide for building CLI applications in Rust using clap. Contains 42 rules across 8 categories, prioritized by impact to guide CLI design, argument parsing, and testing.
When to Apply
Reference these guidelines when:
- Designing new Rust CLI applications
- Adding arguments or subcommands to existing CLIs
- Validating and parsing command-line input
- Writing integration tests for CLI tools
- Improving help text and user experience
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Type-Driven Design | CRITICAL | |
| 2 | Derive API Patterns | CRITICAL | |
| 3 | Argument Configuration | HIGH | |
| 4 | Validation & Parsing | HIGH | |
| 5 | Subcommand Architecture | MEDIUM-HIGH | |
| 6 | Help & Documentation | MEDIUM | |
| 7 | Error Handling | MEDIUM | |
| 8 | Testing Patterns | LOW-MEDIUM | |
Quick Reference
1. Type-Driven Design (CRITICAL)
- Use ValueEnum for enumerated argumentstype-valueenum-enums
- Use Option for truly optional argumentstype-option-optional
- Use PathBuf for file system argumentstype-pathbuf-files
- Use Vec for multiple value argumentstype-vec-multiple
- Use newtypes for semantic distinctiontype-newtype-semantic
- Use bool for simple flagstype-bool-flags
2. Derive API Patterns (CRITICAL)
- Derive Parser for CLI entry pointderive-parser-entry
- Use Command attribute for metadataderive-command-metadata
- Use Subcommand derive for command hierarchiesderive-subcommand-enum
- Derive Args for reusable argument groupsderive-args-reusable
- Use doc comments for help textderive-doc-comments
- Use Global for cross-subcommand optionsderive-global-options
- Propagate version to subcommandsderive-propagate-version
3. Argument Configuration (HIGH)
- Use default_value for sensible defaultsarg-default-value
- Use env for environment variable fallbackarg-env-fallback
- Provide both short and long option namesarg-short-long
- Use conflicts_with for mutually exclusive optionsarg-conflicts-with
- Use requires for dependent argumentsarg-requires
- Use value_name for descriptive placeholdersarg-value-name
4. Validation & Parsing (HIGH)
- Use value_parser for custom validationvalid-value-parser
- Use PossibleValuesParser for string constraintsvalid-possible-values
- Implement FromStr for domain typesvalid-fromstr-types
- Use try_parse for graceful error handlingvalid-try-parse
- Use num_args for value count constraintsvalid-num-args
5. Subcommand Architecture (MEDIUM-HIGH)
- Use nested subcommands for complex CLIssubcmd-nested-hierarchy
- Use struct for subcommand argumentssubcmd-args-struct
- Require subcommand or show helpsubcmd-required-help
- Use ArgGroup for one-of-many requirementssubcmd-arg-groups
- Use external subcommands for plugin systemssubcmd-external
6. Help & Documentation (MEDIUM)
- Generate shell completions with clap_completehelp-shell-completions
- Use next_help_heading for organized helphelp-next-heading
- Use after_help for examples and contexthelp-after-help
- Hide advanced options from default helphelp-hide-options
7. Error Handling (MEDIUM)
- Use appropriate exit codeserror-exit-codes
- Add context to error messageserror-context
- Enable suggestions for typoserror-suggestions
- Use colored output for error visibilityerror-color-styles
8. Testing Patterns (LOW-MEDIUM)
- Use assert_cmd for integration testingtest-assert-cmd
- Use predicates for flexible assertionstest-predicates
- Use assert_fs for temporary test filestest-temp-files
- Use parse_from for unit testing parserstest-parse-from
- Use trycmd for snapshot testingtest-trycmd-snapshots
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |