aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-26 12:41:20 +0100
committerGitHub <[email protected]>2020-08-26 12:41:20 +0100
commitad60b4e6ea1cbbb4c611f56833af90b43c4a5a3e (patch)
tree7cb422505b7cf2d7620f2d25f42f0a7d241b6ff3
parent868aaf2bc61627ae8e5d920c38b2666756743515 (diff)
parent7431ec82c985516213f3283e370b81d067ec0367 (diff)
Merge #5890
5890: Simplify r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/rust-analyzer/src/bin/args.rs21
1 files changed, 4 insertions, 17 deletions
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs
index 41ce5cae9..8ddf1e031 100644
--- a/crates/rust-analyzer/src/bin/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -3,7 +3,7 @@
3//! If run started args, we run the LSP server loop. With a subcommand, we do a 3//! If run started args, we run the LSP server loop. With a subcommand, we do a
4//! one-time batch processing. 4//! one-time batch processing.
5 5
6use std::{env, fmt::Write, path::PathBuf}; 6use std::{env, path::PathBuf};
7 7
8use anyhow::{bail, format_err, Result}; 8use anyhow::{bail, format_err, Result};
9use pico_args::Arguments; 9use pico_args::Arguments;
@@ -108,7 +108,7 @@ impl Args {
108 let mut matches = Arguments::from_env(); 108 let mut matches = Arguments::from_env();
109 109
110 if matches.contains("--version") { 110 if matches.contains("--version") {
111 matches.finish().or_else(handle_extra_flags)?; 111 matches.finish()?;
112 return Ok(Args { 112 return Ok(Args {
113 verbosity: Verbosity::Normal, 113 verbosity: Verbosity::Normal,
114 log_file: None, 114 log_file: None,
@@ -138,7 +138,7 @@ impl Args {
138 let subcommand = match matches.subcommand()? { 138 let subcommand = match matches.subcommand()? {
139 Some(it) => it, 139 Some(it) => it,
140 None => { 140 None => {
141 matches.finish().or_else(handle_extra_flags)?; 141 matches.finish()?;
142 return Ok(Args { verbosity, log_file, command: Command::RunServer }); 142 return Ok(Args { verbosity, log_file, command: Command::RunServer });
143 } 143 }
144 }; 144 };
@@ -217,20 +217,7 @@ impl Args {
217 return Ok(Args { verbosity, log_file: None, command: Command::Help }); 217 return Ok(Args { verbosity, log_file: None, command: Command::Help });
218 } 218 }
219 }; 219 };
220 matches.finish().or_else(handle_extra_flags)?; 220 matches.finish()?;
221 Ok(Args { verbosity, log_file, command }) 221 Ok(Args { verbosity, log_file, command })
222 } 222 }
223} 223}
224
225fn handle_extra_flags(e: pico_args::Error) -> Result<()> {
226 if let pico_args::Error::UnusedArgsLeft(flags) = e {
227 let mut invalid_flags = String::new();
228 for flag in flags {
229 write!(&mut invalid_flags, "{}, ", flag)?;
230 }
231 let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2);
232 bail!("Invalid flags: {}", invalid_flags);
233 } else {
234 bail!(e);
235 }
236}