Make ruff_cli binary a small wrapper around lib (#3398)

This commit is contained in:
Micha Reiser 2023-03-08 12:11:55 +01:00 committed by GitHub
parent d9dfec30eb
commit a3de791f0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 457 additions and 453 deletions

View file

@ -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(())
}