diff --git a/src/cli.rs b/src/cli.rs index c8a4ca1ae94c1..0314203cfa83f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -15,7 +15,7 @@ use crate::settings::types::{FilePattern, PatternPrefixPair, PerFileIgnore, Pyth #[command(version)] #[allow(clippy::struct_excessive_bools)] pub struct Cli { - #[arg(required = true)] + #[arg(required_unless_present_any = ["explain", "generate_shell_completion"])] pub files: Vec, /// Path to the `pyproject.toml` file to use for configuration. #[arg(long)] diff --git a/src/main.rs b/src/main.rs index 94e767a281616..a6c932919c4cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -193,6 +193,16 @@ fn inner_main() -> Result { let log_level = extract_log_level(&cli); set_up_logging(&log_level)?; + if let Some(code) = cli.explain { + commands::explain(&code, cli.format)?; + return Ok(ExitCode::SUCCESS); + } + + if let Some(shell) = cli.generate_shell_completion { + shell.generate(&mut Cli::command(), &mut std::io::stdout()); + return Ok(ExitCode::SUCCESS); + } + // Find the project root and pyproject.toml. let project_root = pyproject::find_project_root(&cli.files); match &project_root { @@ -256,16 +266,6 @@ fn inner_main() -> Result { configuration.show_source = true; } - if let Some(code) = cli.explain { - commands::explain(&code, cli.format)?; - return Ok(ExitCode::SUCCESS); - } - - if let Some(shell) = cli.generate_shell_completion { - shell.generate(&mut Cli::command(), &mut std::io::stdout()); - return Ok(ExitCode::SUCCESS); - } - if cli.show_settings && cli.show_files { eprintln!("Error: specify --show-settings or show-files (not both)."); return Ok(ExitCode::FAILURE);