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.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 66258c860..4cf062f47 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -5,14 +5,14 @@ mod analysis_stats;
5mod analysis_bench; 5mod analysis_bench;
6mod progress_report; 6mod progress_report;
7 7
8use std::{error::Error, fmt::Write, io::Read, path::PathBuf, str::FromStr}; 8use std::{fmt::Write, io::Read, path::PathBuf, str::FromStr};
9 9
10use pico_args::Arguments; 10use pico_args::Arguments;
11use ra_ide::{file_structure, Analysis}; 11use ra_ide::{file_structure, Analysis};
12use ra_prof::profile; 12use ra_prof::profile;
13use ra_syntax::{AstNode, SourceFile}; 13use ra_syntax::{AstNode, SourceFile};
14 14
15type Result<T, E = Box<dyn Error + Send + Sync>> = std::result::Result<T, E>; 15use anyhow::{bail, format_err, Result};
16 16
17fn main() -> Result<()> { 17fn main() -> Result<()> {
18 env_logger::try_init()?; 18 env_logger::try_init()?;
@@ -118,7 +118,7 @@ pub(crate) struct Position {
118} 118}
119 119
120impl FromStr for Position { 120impl FromStr for Position {
121 type Err = Box<dyn std::error::Error + Send + Sync>; 121 type Err = anyhow::Error;
122 fn from_str(s: &str) -> Result<Self> { 122 fn from_str(s: &str) -> Result<Self> {
123 let (path_line, column) = rsplit_at_char(s, ':')?; 123 let (path_line, column) = rsplit_at_char(s, ':')?;
124 let (path, line) = rsplit_at_char(path_line, ':')?; 124 let (path, line) = rsplit_at_char(path_line, ':')?;
@@ -127,7 +127,7 @@ impl FromStr for Position {
127} 127}
128 128
129fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { 129fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> {
130 let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?; 130 let idx = s.rfind(c).ok_or_else(|| format_err!("no `{}` in {}", c, s))?;
131 Ok((&s[..idx], &s[idx + 1..])) 131 Ok((&s[..idx], &s[idx + 1..]))
132} 132}
133 133
@@ -143,12 +143,12 @@ impl Command {
143 matches.contains(["-v", "--verbose"]), 143 matches.contains(["-v", "--verbose"]),
144 matches.contains(["-q", "--quiet"]), 144 matches.contains(["-q", "--quiet"]),
145 ) { 145 ) {
146 (true, _, true) => Err("Invalid flags: -q conflicts with -vv")?, 146 (true, _, true) => bail!("Invalid flags: -q conflicts with -vv"),
147 (true, _, false) => Verbosity::Spammy, 147 (true, _, false) => Verbosity::Spammy,
148 (false, false, false) => Verbosity::Normal, 148 (false, false, false) => Verbosity::Normal,
149 (false, false, true) => Verbosity::Quiet, 149 (false, false, true) => Verbosity::Quiet,
150 (false, true, false) => Verbosity::Verbose, 150 (false, true, false) => Verbosity::Verbose,
151 (false, true, true) => Err("Invalid flags: -q conflicts with -v")?, 151 (false, true, true) => bail!("Invalid flags: -q conflicts with -v"),
152 }; 152 };
153 153
154 let command = match subcommand.as_str() { 154 let command = match subcommand.as_str() {
@@ -242,7 +242,7 @@ ARGS:
242 let path = { 242 let path = {
243 let mut trailing = matches.free()?; 243 let mut trailing = matches.free()?;
244 if trailing.len() != 1 { 244 if trailing.len() != 1 {
245 Err("Invalid flags")?; 245 bail!("Invalid flags");
246 } 246 }
247 trailing.pop().unwrap().into() 247 trailing.pop().unwrap().into()
248 }; 248 };
@@ -318,9 +318,9 @@ fn handle_extra_flags(e: pico_args::Error) -> Result<()> {
318 write!(&mut invalid_flags, "{}, ", flag)?; 318 write!(&mut invalid_flags, "{}, ", flag)?;
319 } 319 }
320 let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2); 320 let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2);
321 Err(format!("Invalid flags: {}", invalid_flags).into()) 321 bail!("Invalid flags: {}", invalid_flags);
322 } else { 322 } else {
323 Err(e.to_string().into()) 323 bail!(e);
324 } 324 }
325} 325}
326 326