aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli/src/main.rs')
-rw-r--r--crates/ra_cli/src/main.rs38
1 files changed, 34 insertions, 4 deletions
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index e6334cf56..ca9275cd4 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -12,6 +12,22 @@ use ra_syntax::{AstNode, SourceFile};
12 12
13type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; 13type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
14 14
15#[derive(Clone, Copy)]
16pub enum Verbosity {
17 Verbose,
18 Normal,
19 Quiet,
20}
21
22impl Verbosity {
23 fn is_verbose(&self) -> bool {
24 match self {
25 Verbosity::Verbose => true,
26 _ => false,
27 }
28 }
29}
30
15fn main() -> Result<()> { 31fn main() -> Result<()> {
16 Logger::with_env().start()?; 32 Logger::with_env().start()?;
17 33
@@ -67,13 +83,27 @@ fn main() -> Result<()> {
67 eprintln!("{}", help::ANALYSIS_STATS_HELP); 83 eprintln!("{}", help::ANALYSIS_STATS_HELP);
68 return Ok(()); 84 return Ok(());
69 } 85 }
70 let verbose = matches.contains(["-v", "--verbose"]); 86 let verbosity = match (
87 matches.contains(["-v", "--verbose"]),
88 matches.contains(["-q", "--quiet"]),
89 ) {
90 (false, false) => Verbosity::Normal,
91 (false, true) => Verbosity::Quiet,
92 (true, false) => Verbosity::Verbose,
93 (true, true) => Err("Invalid flags: -q conflicts with -v")?,
94 };
71 let memory_usage = matches.contains("--memory-usage"); 95 let memory_usage = matches.contains("--memory-usage");
72 let path: String = matches.value_from_str("--path")?.unwrap_or_default();
73 let only = matches.value_from_str(["-o", "--only"])?.map(|v: String| v.to_owned()); 96 let only = matches.value_from_str(["-o", "--only"])?.map(|v: String| v.to_owned());
74 matches.finish().or_else(handle_extra_flags)?; 97 let path = {
98 let mut trailing = matches.free()?;
99 if trailing.len() != 1 {
100 eprintln!("{}", help::ANALYSIS_STATS_HELP);
101 Err("Invalid flags")?;
102 }
103 trailing.pop().unwrap()
104 };
75 analysis_stats::run( 105 analysis_stats::run(
76 verbose, 106 verbosity,
77 memory_usage, 107 memory_usage,
78 path.as_ref(), 108 path.as_ref(),
79 only.as_ref().map(String::as_ref), 109 only.as_ref().map(String::as_ref),