Skip to content

C0029 cli-standard-flags

Rule: A CLI's short flags keep their standard meaning.

Code C0029 (stable, never reused)
Id cli-standard-flags
Category cli
Source spirit_level
Fix by hand
Needs cargo installed

Level per tier

Tier Level Reason
small warn short flags are habits across tools; a different meaning turns a habit into a mistake
small-workspace warn short flags are habits across tools; a different meaning turns a habit into a mistake
medium warn short flags are habits across tools; a different meaning turns a habit into a mistake
big warn short flags are habits across tools; a different meaning turns a habit into a mistake
ai off
embedded off
ui off
egui off
units-strict off
units-paranoid off

Parameters

Name Type Default Meaning
pairs list of strings ["-h=--help", "-V=--version", "-v=--verbose", "-q=--quiet", "-n=--dry-run", "-a=--all", "-o=--output", "-y=--yes"] short flags and the long flag each must stand for

Why

Short flags are muscle memory across tools: -n is a dry run, -q quiet, -y yes. A tool where -n means --name turns a habit into a mistake, and -n on a destructive command then runs it for real.

Example

Options:
  -n, --name <NAME>   <- -n stands for --dry-run

How to fix

Give the flag another short form, or none. The parameter pairs lists each short flag and the long flag it stands for (-n=--dry-run); -f is not in the default list, because some tools use it for --force and others for --format.

Configure

[lints.cli-standard-flags]
level = "deny"
pairs = ["-h=--help", "-V=--version", "-v=--verbose", "-q=--quiet", "-n=--dry-run", "-a=--all", "-o=--output", "-y=--yes"]
reason = "why this project wants it at this level"

Allow one finding in the code with // spirit-level: allow(cli-standard-flags) <reason> (waivers); the code works there too, as in [lints.C0029].