Unify verbosity handling
This commit is contained in:
parent
fa482a9fee
commit
c818f5c65e
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<String> = 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<String> = matches.opt_value_from_str("--highlight")?;
|
||||
let complete_path: Option<String> = 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!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user