Include both ruff help and ruff help check in README (#2325)

This commit is contained in:
Charlie Marsh
2023-01-29 17:01:15 -05:00
committed by GitHub
parent 2ad29089af
commit 64fb0bd2cc
4 changed files with 128 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
//! This library only exists to enable the Ruff internal tooling (`ruff_dev`)
//! to automatically update the `ruff --help` output in the `README.md`.
//! to automatically update the `ruff help` output in the `README.md`.
//!
//! For the actual Ruff library, see [`ruff`].
#![forbid(unsafe_code)]
@@ -10,7 +10,26 @@ mod args;
use clap::CommandFactory;
/// Returns the output of `ruff --help`.
pub fn help() -> String {
/// Returns the output of `ruff help`.
pub fn command_help() -> String {
args::Args::command().render_help().to_string()
}
/// Returns the output of `ruff help check`.
pub fn subcommand_help() -> String {
let output = args::Args::command()
.find_subcommand_mut("check")
.expect("`check` subcommand not found")
.render_help()
.to_string();
// Replace the header, to fix Clap's omission of "ruff" on the "Usage: check" line.
let header =
"Run Ruff on the given files or directories (default)\n\nUsage: check [OPTIONS] [FILES]...";
let replacement =
"Run Ruff on the given files or directories\n\nUsage: ruff check [OPTIONS] [FILES]...";
let output = output
.strip_prefix(header)
.expect("`output` does not start expected header");
format!("{replacement}{output}")
}