From c818f5c65e67c93a55cbf7b1b6ded983d8f392b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Feb 2020 18:05:45 +0100 Subject: Unify verbosity handling --- crates/ra_cli/src/analysis_bench.rs | 10 +++++----- crates/ra_cli/src/main.rs | 34 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs index 3f10ed400..83f95555f 100644 --- a/crates/ra_cli/src/analysis_bench.rs +++ b/crates/ra_cli/src/analysis_bench.rs @@ -13,7 +13,7 @@ use ra_db::{ }; use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; -use crate::{load_cargo::load_cargo, Result}; +use crate::{load_cargo::load_cargo, Result, Verbosity}; pub(crate) struct Position { path: PathBuf, @@ -41,7 +41,7 @@ pub(crate) enum Op { GotoDef(Position), } -pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { +pub(crate) fn run(verbosity: Verbosity, path: &Path, op: Op) -> Result<()> { ra_prof::init(); let start = Instant::now(); @@ -79,7 +79,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { analysis.diagnostics(file_id).unwrap(); analysis.highlight_as_html(file_id, false).unwrap() }); - if verbose { + if verbosity.is_verbose() { println!("\n{}", res); } } @@ -98,13 +98,13 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { if is_completion { let res = do_work(&mut host, file_id, |analysis| analysis.completions(file_postion)); - if verbose { + if verbosity.is_verbose() { println!("\n{:#?}", res); } } else { let res = do_work(&mut host, file_id, |analysis| analysis.goto_definition(file_postion)); - if verbose { + if verbosity.is_verbose() { println!("\n{:#?}", res); } } diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index f952d0f6c..58fea2cd4 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -48,8 +48,8 @@ fn main() -> Result<()> { randomize, )?; } - Command::Bench { verbose, path, op } => { - analysis_bench::run(verbose, path.as_ref(), op)?; + Command::Bench { verbosity, path, op } => { + analysis_bench::run(verbosity, path.as_ref(), op)?; } Command::HelpPrinted => (), } @@ -97,7 +97,7 @@ enum Command { path: PathBuf, }, Bench { - verbose: bool, + verbosity: Verbosity, path: PathBuf, op: analysis_bench::Op, }, @@ -109,6 +109,19 @@ impl Command { let mut matches = Arguments::from_env(); let subcommand = matches.subcommand()?.unwrap_or_default(); + let verbosity = match ( + matches.contains(["-vv", "--spammy"]), + matches.contains(["-v", "--verbose"]), + matches.contains(["-q", "--quiet"]), + ) { + (true, _, true) => Err("Invalid flags: -q conflicts with -vv")?, + (true, _, false) => Verbosity::Spammy, + (false, false, false) => Verbosity::Normal, + (false, false, true) => Verbosity::Quiet, + (false, true, false) => Verbosity::Verbose, + (false, true, true) => Err("Invalid flags: -q conflicts with -v")?, + }; + let command = match subcommand.as_str() { "parse" => { if matches.contains(["-h", "--help"]) { @@ -193,18 +206,6 @@ ARGS: return Ok(Command::HelpPrinted); } - let verbosity = match ( - matches.contains(["-vv", "--spammy"]), - matches.contains(["-v", "--verbose"]), - matches.contains(["-q", "--quiet"]), - ) { - (true, _, true) => Err("Invalid flags: -q conflicts with -vv")?, - (true, _, false) => Verbosity::Spammy, - (false, false, false) => Verbosity::Normal, - (false, false, true) => Verbosity::Quiet, - (false, true, false) => Verbosity::Verbose, - (false, true, true) => Err("Invalid flags: -q conflicts with -v")?, - }; let randomize = matches.contains("--randomize"); let memory_usage = matches.contains("--memory-usage"); let only: Option = matches.opt_value_from_str(["-o", "--only"])?; @@ -242,7 +243,6 @@ ARGS: return Ok(Command::HelpPrinted); } - let verbose = matches.contains(["-v", "--verbose"]); let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default(); let highlight_path: Option = matches.opt_value_from_str("--highlight")?; let complete_path: Option = matches.opt_value_from_str("--complete")?; @@ -255,7 +255,7 @@ ARGS: "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" ), }; - Command::Bench { verbose, path, op } + Command::Bench { verbosity, path, op } } _ => { eprintln!( -- cgit v1.2.3