mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
Merge #7350
7350: Update pico-args r=matklad a=kjeremy Should maintain existing behavior Co-authored-by: kjeremy <kjeremy@gmail.com>
This commit is contained in:
commit
de5aabd48b
5 changed files with 40 additions and 25 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1196,9 +1196,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pico-args"
|
||||
version = "0.3.4"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28b9b4df73455c861d7cbf8be42f01d3b373ed7f02e378d55fa84eafc6f638b1"
|
||||
checksum = "d70072c20945e1ab871c472a285fc772aefd4f5407723c206242f2c6f94595d6"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
|
|
|
@ -24,7 +24,7 @@ jod-thread = "0.1.0"
|
|||
log = "0.4.8"
|
||||
lsp-types = { version = "0.86.0", features = ["proposed"] }
|
||||
parking_lot = "0.11.0"
|
||||
pico-args = "0.3.1"
|
||||
pico-args = "0.4.0"
|
||||
oorandom = "11.1.2"
|
||||
rustc-hash = "1.1.0"
|
||||
serde = { version = "1.0.106", features = ["derive"] }
|
||||
|
|
|
@ -109,7 +109,7 @@ impl Args {
|
|||
let mut matches = Arguments::from_env();
|
||||
|
||||
if matches.contains("--version") {
|
||||
matches.finish()?;
|
||||
finish_args(matches)?;
|
||||
return Ok(Args {
|
||||
verbosity: Verbosity::Normal,
|
||||
log_file: None,
|
||||
|
@ -143,7 +143,7 @@ impl Args {
|
|||
let subcommand = match matches.subcommand()? {
|
||||
Some(it) => it,
|
||||
None => {
|
||||
matches.finish()?;
|
||||
finish_args(matches)?;
|
||||
return Ok(Args { verbosity, log_file, command: Command::RunServer });
|
||||
}
|
||||
};
|
||||
|
@ -160,7 +160,7 @@ impl Args {
|
|||
load_output_dirs: matches.contains("--load-output-dirs"),
|
||||
with_proc_macro: matches.contains("--with-proc-macro"),
|
||||
path: matches
|
||||
.free_from_str()?
|
||||
.opt_free_from_str()?
|
||||
.ok_or_else(|| format_err!("expected positional argument"))?,
|
||||
}),
|
||||
"analysis-bench" => Command::Bench(BenchCmd {
|
||||
|
@ -187,21 +187,21 @@ impl Args {
|
|||
load_output_dirs: matches.contains("--load-output-dirs"),
|
||||
with_proc_macro: matches.contains("--with-proc-macro"),
|
||||
path: matches
|
||||
.free_from_str()?
|
||||
.opt_free_from_str()?
|
||||
.ok_or_else(|| format_err!("expected positional argument"))?,
|
||||
}),
|
||||
"diagnostics" => Command::Diagnostics {
|
||||
load_output_dirs: matches.contains("--load-output-dirs"),
|
||||
with_proc_macro: matches.contains("--with-proc-macro"),
|
||||
path: matches
|
||||
.free_from_str()?
|
||||
.opt_free_from_str()?
|
||||
.ok_or_else(|| format_err!("expected positional argument"))?,
|
||||
},
|
||||
"proc-macro" => Command::ProcMacro,
|
||||
"ssr" => Command::Ssr {
|
||||
rules: {
|
||||
let mut acc = Vec::new();
|
||||
while let Some(rule) = matches.free_from_str()? {
|
||||
while let Some(rule) = matches.opt_free_from_str()? {
|
||||
acc.push(rule);
|
||||
}
|
||||
acc
|
||||
|
@ -211,7 +211,7 @@ impl Args {
|
|||
debug_snippet: matches.opt_value_from_str("--debug")?,
|
||||
patterns: {
|
||||
let mut acc = Vec::new();
|
||||
while let Some(rule) = matches.free_from_str()? {
|
||||
while let Some(rule) = matches.opt_free_from_str()? {
|
||||
acc.push(rule);
|
||||
}
|
||||
acc
|
||||
|
@ -222,7 +222,14 @@ impl Args {
|
|||
return Ok(Args { verbosity, log_file: None, command: Command::Help });
|
||||
}
|
||||
};
|
||||
matches.finish()?;
|
||||
finish_args(matches)?;
|
||||
Ok(Args { verbosity, log_file, command })
|
||||
}
|
||||
}
|
||||
|
||||
fn finish_args(args: Arguments) -> Result<()> {
|
||||
if !args.finish().is_empty() {
|
||||
bail!("Unused arguments.");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ doctest = false
|
|||
[dependencies]
|
||||
anyhow = "1.0.26"
|
||||
flate2 = "1.0"
|
||||
pico-args = "0.3.1"
|
||||
pico-args = "0.4.0"
|
||||
proc-macro2 = "1.0.8"
|
||||
quote = "1.0.2"
|
||||
ungrammar = "1.9"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
use std::env;
|
||||
|
||||
use anyhow::bail;
|
||||
use codegen::CodegenCmd;
|
||||
use pico_args::Arguments;
|
||||
use xshell::{cmd, cp, pushd};
|
||||
|
@ -76,7 +77,7 @@ FLAGS:
|
|||
|
||||
let client_opt = args.opt_value_from_str("--client")?;
|
||||
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
|
||||
InstallCmd {
|
||||
client: if server { None } else { Some(client_opt.unwrap_or_default()) },
|
||||
|
@ -86,53 +87,53 @@ FLAGS:
|
|||
}
|
||||
"codegen" => {
|
||||
let features = args.contains("--features");
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
CodegenCmd { features }.run()
|
||||
}
|
||||
"format" => {
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
run_rustfmt(Mode::Overwrite)
|
||||
}
|
||||
"install-pre-commit-hook" => {
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
pre_commit::install_hook()
|
||||
}
|
||||
"lint" => {
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
run_clippy()
|
||||
}
|
||||
"fuzz-tests" => {
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
run_fuzzer()
|
||||
}
|
||||
"pre-cache" => {
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
PreCacheCmd.run()
|
||||
}
|
||||
"release" => {
|
||||
let dry_run = args.contains("--dry-run");
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
ReleaseCmd { dry_run }.run()
|
||||
}
|
||||
"promote" => {
|
||||
let dry_run = args.contains("--dry-run");
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
PromoteCmd { dry_run }.run()
|
||||
}
|
||||
"dist" => {
|
||||
let nightly = args.contains("--nightly");
|
||||
let client_version: Option<String> = args.opt_value_from_str("--client")?;
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
DistCmd { nightly, client_version }.run()
|
||||
}
|
||||
"metrics" => {
|
||||
let dry_run = args.contains("--dry-run");
|
||||
args.finish()?;
|
||||
finish_args(args)?;
|
||||
MetricsCmd { dry_run }.run()
|
||||
}
|
||||
"bb" => {
|
||||
let suffix: String = args.free_from_str()?.unwrap();
|
||||
args.finish()?;
|
||||
let suffix: String = args.free_from_str()?;
|
||||
finish_args(args)?;
|
||||
cmd!("cargo build --release").run()?;
|
||||
cp("./target/release/rust-analyzer", format!("./target/rust-analyzer-{}", suffix))?;
|
||||
Ok(())
|
||||
|
@ -161,3 +162,10 @@ SUBCOMMANDS:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn finish_args(args: Arguments) -> Result<()> {
|
||||
if !args.finish().is_empty() {
|
||||
bail!("Unused arguments.");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue