From db0aaeca33d430de00587958f82844f088d84a30 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Tue, 19 Jan 2021 11:56:45 -0500 Subject: Update pico-args Should maintains existing behavior --- Cargo.lock | 4 ++-- crates/rust-analyzer/Cargo.toml | 2 +- crates/rust-analyzer/src/bin/args.rs | 23 +++++++++++++++-------- xtask/Cargo.toml | 2 +- xtask/src/main.rs | 34 +++++++++++++++++++++------------- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 901784bec..b06f32913 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1205,9 +1205,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" diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 3cb45b030..268c00942 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -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"] } diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs index 0a471154e..7d917946e 100644 --- a/crates/rust-analyzer/src/bin/args.rs +++ b/crates/rust-analyzer/src/bin/args.rs @@ -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(()) +} diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 4abc7b053..4e6b439fd 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -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" diff --git a/xtask/src/main.rs b/xtask/src/main.rs index c3e5c7326..5a99f4a76 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -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 = 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(()) +} -- cgit v1.2.3