mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Make ruff_cli
binary a small wrapper around lib
(#3398)
This commit is contained in:
parent
d9dfec30eb
commit
a3de791f0a
9 changed files with 457 additions and 453 deletions
|
@ -8,28 +8,39 @@ pub const REGENERATE_ALL_COMMAND: &str = "cargo dev generate-all";
|
|||
|
||||
#[derive(clap::Args)]
|
||||
pub struct Args {
|
||||
/// Write the generated artifacts to stdout (rather than to the filesystem).
|
||||
#[arg(long)]
|
||||
dry_run: bool,
|
||||
#[arg(long, default_value_t, value_enum)]
|
||||
mode: Mode,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, clap::ValueEnum, Default)]
|
||||
pub enum Mode {
|
||||
/// Update the content in the `configuration.md`
|
||||
#[default]
|
||||
Write,
|
||||
|
||||
/// Don't write to the file, check if the file is up-to-date and error if not
|
||||
#[arg(long)]
|
||||
check: bool,
|
||||
Check,
|
||||
|
||||
/// Write the generated help to stdout (rather than to `docs/configuration.md`).
|
||||
DryRun,
|
||||
}
|
||||
|
||||
impl Mode {
|
||||
const fn is_check(self) -> bool {
|
||||
matches!(self, Mode::Check)
|
||||
}
|
||||
|
||||
pub(crate) const fn is_dry_run(self) -> bool {
|
||||
matches!(self, Mode::DryRun)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main(args: &Args) -> Result<()> {
|
||||
// Not checked in
|
||||
if !args.check {
|
||||
generate_docs::main(&generate_docs::Args {
|
||||
dry_run: args.dry_run,
|
||||
})?;
|
||||
if !args.mode.is_check() {
|
||||
generate_docs::main(&generate_docs::Args { dry_run: true })?;
|
||||
}
|
||||
generate_json_schema::main(&generate_json_schema::Args {
|
||||
dry_run: args.dry_run,
|
||||
check: args.check,
|
||||
})?;
|
||||
generate_cli_help::main(&generate_cli_help::Args {
|
||||
dry_run: args.dry_run,
|
||||
check: args.check,
|
||||
})?;
|
||||
generate_json_schema::main(&generate_json_schema::Args { mode: args.mode })?;
|
||||
generate_cli_help::main(&generate_cli_help::Args { mode: args.mode })?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue