Add support for providing command-line arguments via `argfile` (#4087)

This commit is contained in:
Charlie Marsh 2023-04-25 17:58:21 -06:00 committed by GitHub
parent 4df7bc0bcd
commit 7266eb0d69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

13
Cargo.lock generated
View File

@ -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",

View File

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

View File

@ -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"