aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-22 12:55:18 +0100
committerGitHub <[email protected]>2020-04-22 12:55:18 +0100
commitcb0a24104cc5ad15d40e47d92fbdb63683adf8a0 (patch)
treefe8e38d620240606b136c9b70cf76f0deaadbb13 /crates
parente7bb260fbb988341a2afcd7b2acdeffb301a49c1 (diff)
parent165f5c65772a157d842f766100a0ecc30d8ef351 (diff)
Merge #4082
4082: Don't panic on `rust-analyzer --help` r=matklad a=eminence Special case handling for `-h` and `--help` if no subcommand is given. Closes #4068 Co-authored-by: Andrew Chin <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/bin/args.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs
index b14409c39..8e3ca9343 100644
--- a/crates/rust-analyzer/src/bin/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -75,6 +75,10 @@ impl Args {
75 let subcommand = match matches.subcommand()? { 75 let subcommand = match matches.subcommand()? {
76 Some(it) => it, 76 Some(it) => it,
77 None => { 77 None => {
78 if matches.contains(["-h", "--help"]) {
79 print_subcommands();
80 return Ok(Err(HelpPrinted));
81 }
78 matches.finish().or_else(handle_extra_flags)?; 82 matches.finish().or_else(handle_extra_flags)?;
79 return Ok(Ok(Args { verbosity, command: Command::RunServer })); 83 return Ok(Ok(Args { verbosity, command: Command::RunServer }));
80 } 84 }
@@ -267,8 +271,17 @@ ARGS:
267 } 271 }
268 "proc-macro" => Command::ProcMacro, 272 "proc-macro" => Command::ProcMacro,
269 _ => { 273 _ => {
270 eprintln!( 274 print_subcommands();
271 "\ 275 return Ok(Err(HelpPrinted));
276 }
277 };
278 Ok(Ok(Args { verbosity, command }))
279 }
280}
281
282fn print_subcommands() {
283 eprintln!(
284 "\
272rust-analyzer 285rust-analyzer
273 286
274USAGE: 287USAGE:
@@ -285,12 +298,7 @@ SUBCOMMANDS:
285 proc-macro 298 proc-macro
286 parse 299 parse
287 symbols" 300 symbols"
288 ); 301 )
289 return Ok(Err(HelpPrinted));
290 }
291 };
292 Ok(Ok(Args { verbosity, command }))
293 }
294} 302}
295 303
296pub(crate) struct HelpPrinted; 304pub(crate) struct HelpPrinted;