diff --git a/Cargo.lock b/Cargo.lock index 6b87f9ec4f3e6..c9fe444f19da7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,15 @@ version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +[[package]] +name = "argfile" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "265f5108974489a217d5098cd81666b60480c8dd67302acbbe7cbdd8aa09d638" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "ascii" version = "1.1.0" @@ -1503,6 +1512,9 @@ name = "os_str_bytes" version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" +dependencies = [ + "memchr", +] [[package]] name = "output_vt100" @@ -2085,6 +2097,7 @@ version = "0.0.263" dependencies = [ "annotate-snippets 0.9.1", "anyhow", + "argfile", "assert_cmd", "atty", "bincode", diff --git a/crates/ruff_cli/Cargo.toml b/crates/ruff_cli/Cargo.toml index 4225b7d06fad4..7df093bd53640 100644 --- a/crates/ruff_cli/Cargo.toml +++ b/crates/ruff_cli/Cargo.toml @@ -29,6 +29,7 @@ ruff_python_ast = { path = "../ruff_python_ast" } annotate-snippets = { version = "0.9.1", features = ["color"] } anyhow = { workspace = true } +argfile = { version = "0.1.5" } atty = { version = "0.2.14" } bincode = { version = "1.3.3" } bitflags = { workspace = true } diff --git a/crates/ruff_cli/src/bin/ruff.rs b/crates/ruff_cli/src/bin/ruff.rs index 3a00d1d93d873..0c4ea2ef4d5b9 100644 --- a/crates/ruff_cli/src/bin/ruff.rs +++ b/crates/ruff_cli/src/bin/ruff.rs @@ -1,6 +1,6 @@ -use clap::{Parser, Subcommand}; use std::process::ExitCode; +use clap::{Parser, Subcommand}; use colored::Colorize; use ruff_cli::args::{Args, Command}; @@ -23,14 +23,17 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; pub fn main() -> ExitCode { - let mut args: Vec<_> = wild::args().collect(); + let args = wild::args_os(); + let mut args = + argfile::expand_args_from(args, argfile::parse_fromfile, argfile::PREFIX).unwrap(); // Clap doesn't support default subcommands but we want to run `check` by // default for convenience and backwards-compatibility, so we just // preprocess the arguments accordingly before passing them to Clap. if let Some(arg) = args.get(1) { - if !Command::has_subcommand(rewrite_legacy_subcommand(arg)) - && arg != "-h" + if arg.to_str().map_or(false, |arg| { + !Command::has_subcommand(rewrite_legacy_subcommand(arg)) + }) && arg != "-h" && arg != "--help" && arg != "-V" && arg != "--version"