From 3ef916061b208ce6f746562bc732b4a437639505 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Feb 2020 18:09:07 +0100 Subject: More precise types --- crates/ra_cli/src/main.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'crates') diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 58fea2cd4..5302f6ed2 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -12,12 +12,15 @@ use ra_ide::{file_structure, Analysis}; use ra_prof::profile; use ra_syntax::{AstNode, SourceFile}; -type Result = std::result::Result>; +type Result> = std::result::Result; fn main() -> Result<()> { env_logger::try_init()?; - let command = Command::from_args()?; + let command = match Command::from_args()? { + Ok(it) => it, + Err(HelpPrinted) => return Ok(()), + }; match command { Command::Parse { no_dump } => { let _p = profile("parsing"); @@ -51,7 +54,6 @@ fn main() -> Result<()> { Command::Bench { verbosity, path, op } => { analysis_bench::run(verbosity, path.as_ref(), op)?; } - Command::HelpPrinted => (), } Ok(()) @@ -101,11 +103,12 @@ enum Command { path: PathBuf, op: analysis_bench::Op, }, - HelpPrinted, } +struct HelpPrinted; + impl Command { - fn from_args() -> Result { + fn from_args() -> Result> { let mut matches = Arguments::from_env(); let subcommand = matches.subcommand()?.unwrap_or_default(); @@ -136,7 +139,7 @@ FLAGS: -h, --help Prints help inforamtion --no-dump" ); - return Ok(Command::HelpPrinted); + return Ok(Err(HelpPrinted)); } let no_dump = matches.contains("--no-dump"); @@ -155,7 +158,7 @@ USAGE: FLAGS: -h, --help Prints help inforamtion" ); - return Ok(Command::HelpPrinted); + return Ok(Err(HelpPrinted)); } matches.finish().or_else(handle_extra_flags)?; @@ -175,7 +178,7 @@ FLAGS: -h, --help Prints help information -r, --rainbow" ); - return Ok(Command::HelpPrinted); + return Ok(Err(HelpPrinted)); } let rainbow = matches.contains(["-r", "--rainbow"]); @@ -203,7 +206,7 @@ OPTIONS: ARGS: " ); - return Ok(Command::HelpPrinted); + return Ok(Err(HelpPrinted)); } let randomize = matches.contains("--randomize"); @@ -240,7 +243,7 @@ OPTIONS: ARGS: Project to analyse" ); - return Ok(Command::HelpPrinted); + return Ok(Err(HelpPrinted)); } let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default(); @@ -275,10 +278,10 @@ SUBCOMMANDS: parse symbols" ); - return Ok(Command::HelpPrinted); + return Ok(Err(HelpPrinted)); } }; - Ok(command) + Ok(Ok(command)) } } -- cgit v1.2.3