Show --no-X variants in CLI help (#7504)

I'd really like this to render as `--preview / --no-preview`, but I
looked for a while in the Clap internals and issue tracker
(https://github.com/clap-rs/clap/issues/815) and I really can't figure
out a way to do it -- this seems like the best we can do? It's also what
they do in Orogene.

Closes https://github.com/astral-sh/ruff/issues/7486.
This commit is contained in:
Charlie Marsh 2023-09-19 08:27:30 -04:00 committed by GitHub
parent 94b68f201b
commit 97510c888b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View file

@ -77,16 +77,19 @@ pub struct CheckCommand {
/// List of files or directories to check. /// List of files or directories to check.
pub files: Vec<PathBuf>, pub files: Vec<PathBuf>,
/// Attempt to automatically fix lint violations. /// Attempt to automatically fix lint violations.
/// Use `--no-fix` to disable.
#[arg(long, overrides_with("no_fix"))] #[arg(long, overrides_with("no_fix"))]
fix: bool, fix: bool,
#[clap(long, overrides_with("fix"), hide = true)] #[clap(long, overrides_with("fix"), hide = true)]
no_fix: bool, no_fix: bool,
/// Show violations with source code. /// Show violations with source code.
/// Use `--no-show-source` to disable.
#[arg(long, overrides_with("no_show_source"))] #[arg(long, overrides_with("no_show_source"))]
show_source: bool, show_source: bool,
#[clap(long, overrides_with("show_source"), hide = true)] #[clap(long, overrides_with("show_source"), hide = true)]
no_show_source: bool, no_show_source: bool,
/// Show an enumeration of all autofixed lint violations. /// Show an enumeration of all autofixed lint violations.
/// Use `--no-show-fixes` to disable.
#[arg(long, overrides_with("no_show_fixes"))] #[arg(long, overrides_with("no_show_fixes"))]
show_fixes: bool, show_fixes: bool,
#[clap(long, overrides_with("show_fixes"), hide = true)] #[clap(long, overrides_with("show_fixes"), hide = true)]
@ -98,6 +101,7 @@ pub struct CheckCommand {
#[arg(short, long)] #[arg(short, long)]
pub watch: bool, pub watch: bool,
/// Fix any fixable lint violations, but don't report on leftover violations. Implies `--fix`. /// Fix any fixable lint violations, but don't report on leftover violations. Implies `--fix`.
/// Use `--no-fix-only` to disable.
#[arg(long, overrides_with("no_fix_only"))] #[arg(long, overrides_with("no_fix_only"))]
fix_only: bool, fix_only: bool,
#[clap(long, overrides_with("fix_only"), hide = true)] #[clap(long, overrides_with("fix_only"), hide = true)]
@ -115,6 +119,7 @@ pub struct CheckCommand {
#[arg(long, value_enum)] #[arg(long, value_enum)]
pub target_version: Option<PythonVersion>, pub target_version: Option<PythonVersion>,
/// Enable preview mode; checks will include unstable rules and fixes. /// Enable preview mode; checks will include unstable rules and fixes.
/// Use `--no-preview` to disable.
#[arg(long, overrides_with("no_preview"))] #[arg(long, overrides_with("no_preview"))]
preview: bool, preview: bool,
#[clap(long, overrides_with("preview"), hide = true)] #[clap(long, overrides_with("preview"), hide = true)]
@ -226,6 +231,7 @@ pub struct CheckCommand {
)] )]
pub extend_unfixable: Option<Vec<RuleSelector>>, pub extend_unfixable: Option<Vec<RuleSelector>>,
/// Respect file exclusions via `.gitignore` and other standard ignore files. /// Respect file exclusions via `.gitignore` and other standard ignore files.
/// Use `--no-respect-gitignore` to disable.
#[arg( #[arg(
long, long,
overrides_with("no_respect_gitignore"), overrides_with("no_respect_gitignore"),
@ -235,6 +241,7 @@ pub struct CheckCommand {
#[clap(long, overrides_with("respect_gitignore"), hide = true)] #[clap(long, overrides_with("respect_gitignore"), hide = true)]
no_respect_gitignore: bool, no_respect_gitignore: bool,
/// Enforce exclusions, even for paths passed to Ruff directly on the command-line. /// Enforce exclusions, even for paths passed to Ruff directly on the command-line.
/// Use `--no-force-exclude` to disable.
#[arg( #[arg(
long, long,
overrides_with("no_force_exclude"), overrides_with("no_force_exclude"),
@ -341,6 +348,7 @@ pub struct FormatCommand {
#[arg(long, conflicts_with = "isolated")] #[arg(long, conflicts_with = "isolated")]
pub config: Option<PathBuf>, pub config: Option<PathBuf>,
/// Respect file exclusions via `.gitignore` and other standard ignore files. /// Respect file exclusions via `.gitignore` and other standard ignore files.
/// Use `--no-respect-gitignore` to disable.
#[arg( #[arg(
long, long,
overrides_with("no_respect_gitignore"), overrides_with("no_respect_gitignore"),
@ -350,6 +358,7 @@ pub struct FormatCommand {
#[clap(long, overrides_with("respect_gitignore"), hide = true)] #[clap(long, overrides_with("respect_gitignore"), hide = true)]
no_respect_gitignore: bool, no_respect_gitignore: bool,
/// Enforce exclusions, even for paths passed to Ruff directly on the command-line. /// Enforce exclusions, even for paths passed to Ruff directly on the command-line.
/// Use `--no-force-exclude` to disable.
#[arg( #[arg(
long, long,
overrides_with("no_force_exclude"), overrides_with("no_force_exclude"),
@ -369,6 +378,7 @@ pub struct FormatCommand {
pub stdin_filename: Option<PathBuf>, pub stdin_filename: Option<PathBuf>,
/// Enable preview mode; checks will include unstable rules and fixes. /// Enable preview mode; checks will include unstable rules and fixes.
/// Use `--no-preview` to disable.
#[arg(long, overrides_with("no_preview"), hide = true)] #[arg(long, overrides_with("no_preview"), hide = true)]
preview: bool, preview: bool,
#[clap(long, overrides_with("preview"), hide = true)] #[clap(long, overrides_with("preview"), hide = true)]

View file

@ -193,17 +193,17 @@ Arguments:
Options: Options:
--fix --fix
Attempt to automatically fix lint violations Attempt to automatically fix lint violations. Use `--no-fix` to disable
--show-source --show-source
Show violations with source code Show violations with source code. Use `--no-show-source` to disable
--show-fixes --show-fixes
Show an enumeration of all autofixed lint violations Show an enumeration of all autofixed lint violations. Use `--no-show-fixes` to disable
--diff --diff
Avoid writing any fixed files back; instead, output a diff for each changed file to stdout. Implies `--fix-only` Avoid writing any fixed files back; instead, output a diff for each changed file to stdout. Implies `--fix-only`
-w, --watch -w, --watch
Run in watch mode by re-running whenever files change Run in watch mode by re-running whenever files change
--fix-only --fix-only
Fix any fixable lint violations, but don't report on leftover violations. Implies `--fix` Fix any fixable lint violations, but don't report on leftover violations. Implies `--fix`. Use `--no-fix-only` to disable
--ignore-noqa --ignore-noqa
Ignore any `# noqa` comments Ignore any `# noqa` comments
--format <FORMAT> --format <FORMAT>
@ -213,7 +213,7 @@ Options:
--target-version <TARGET_VERSION> --target-version <TARGET_VERSION>
The minimum Python version that should be supported [possible values: py37, py38, py39, py310, py311, py312] The minimum Python version that should be supported [possible values: py37, py38, py39, py310, py311, py312]
--preview --preview
Enable preview mode; checks will include unstable rules and fixes Enable preview mode; checks will include unstable rules and fixes. Use `--no-preview` to disable
--config <CONFIG> --config <CONFIG>
Path to the `pyproject.toml` or `ruff.toml` file to use for configuration Path to the `pyproject.toml` or `ruff.toml` file to use for configuration
--statistics --statistics
@ -248,8 +248,8 @@ Rule selection:
File selection: File selection:
--exclude <FILE_PATTERN> List of paths, used to omit files and/or directories from analysis --exclude <FILE_PATTERN> List of paths, used to omit files and/or directories from analysis
--extend-exclude <FILE_PATTERN> Like --exclude, but adds additional files and directories on top of those already excluded --extend-exclude <FILE_PATTERN> Like --exclude, but adds additional files and directories on top of those already excluded
--respect-gitignore Respect file exclusions via `.gitignore` and other standard ignore files --respect-gitignore Respect file exclusions via `.gitignore` and other standard ignore files. Use `--no-respect-gitignore` to disable
--force-exclude Enforce exclusions, even for paths passed to Ruff directly on the command-line --force-exclude Enforce exclusions, even for paths passed to Ruff directly on the command-line. Use `--no-force-exclude` to disable
Miscellaneous: Miscellaneous:
-n, --no-cache -n, --no-cache