mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
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 <achin@eminence32.net>
This commit is contained in:
commit
cb0a24104c
1 changed files with 16 additions and 8 deletions
|
@ -75,6 +75,10 @@ impl Args {
|
||||||
let subcommand = match matches.subcommand()? {
|
let subcommand = match matches.subcommand()? {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => {
|
None => {
|
||||||
|
if matches.contains(["-h", "--help"]) {
|
||||||
|
print_subcommands();
|
||||||
|
return Ok(Err(HelpPrinted));
|
||||||
|
}
|
||||||
matches.finish().or_else(handle_extra_flags)?;
|
matches.finish().or_else(handle_extra_flags)?;
|
||||||
return Ok(Ok(Args { verbosity, command: Command::RunServer }));
|
return Ok(Ok(Args { verbosity, command: Command::RunServer }));
|
||||||
}
|
}
|
||||||
|
@ -267,8 +271,17 @@ ARGS:
|
||||||
}
|
}
|
||||||
"proc-macro" => Command::ProcMacro,
|
"proc-macro" => Command::ProcMacro,
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!(
|
print_subcommands();
|
||||||
"\
|
return Ok(Err(HelpPrinted));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(Ok(Args { verbosity, command }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_subcommands() {
|
||||||
|
eprintln!(
|
||||||
|
"\
|
||||||
rust-analyzer
|
rust-analyzer
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
|
@ -285,12 +298,7 @@ SUBCOMMANDS:
|
||||||
proc-macro
|
proc-macro
|
||||||
parse
|
parse
|
||||||
symbols"
|
symbols"
|
||||||
);
|
)
|
||||||
return Ok(Err(HelpPrinted));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(Ok(Args { verbosity, command }))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct HelpPrinted;
|
pub(crate) struct HelpPrinted;
|
||||||
|
|
Loading…
Reference in a new issue