Skip to content

Commit

Permalink
Add support for providing command-line arguments via argfile (#4087)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Apr 25, 2023
1 parent 4df7bc0 commit 7266eb0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/ruff_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
11 changes: 7 additions & 4 deletions crates/ruff_cli/src/bin/ruff.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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"
Expand Down

0 comments on commit 7266eb0

Please sign in to comment.