diff options
author | Aleksey Kladov <[email protected]> | 2020-02-17 17:09:07 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-17 17:09:07 +0000 |
commit | 3ef916061b208ce6f746562bc732b4a437639505 (patch) | |
tree | 51df022b777dfb71be8af6b2f34599d6c13fab07 /crates/ra_cli | |
parent | c818f5c65e67c93a55cbf7b1b6ded983d8f392b8 (diff) |
More precise types
Diffstat (limited to 'crates/ra_cli')
-rw-r--r-- | crates/ra_cli/src/main.rs | 27 |
1 files changed, 15 insertions, 12 deletions
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}; | |||
12 | use ra_prof::profile; | 12 | use ra_prof::profile; |
13 | use ra_syntax::{AstNode, SourceFile}; | 13 | use ra_syntax::{AstNode, SourceFile}; |
14 | 14 | ||
15 | type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; | 15 | type Result<T, E = Box<dyn Error + Send + Sync>> = std::result::Result<T, E>; |
16 | 16 | ||
17 | fn main() -> Result<()> { | 17 | fn main() -> Result<()> { |
18 | env_logger::try_init()?; | 18 | env_logger::try_init()?; |
19 | 19 | ||
20 | let command = Command::from_args()?; | 20 | let command = match Command::from_args()? { |
21 | Ok(it) => it, | ||
22 | Err(HelpPrinted) => return Ok(()), | ||
23 | }; | ||
21 | match command { | 24 | match command { |
22 | Command::Parse { no_dump } => { | 25 | Command::Parse { no_dump } => { |
23 | let _p = profile("parsing"); | 26 | let _p = profile("parsing"); |
@@ -51,7 +54,6 @@ fn main() -> Result<()> { | |||
51 | Command::Bench { verbosity, path, op } => { | 54 | Command::Bench { verbosity, path, op } => { |
52 | analysis_bench::run(verbosity, path.as_ref(), op)?; | 55 | analysis_bench::run(verbosity, path.as_ref(), op)?; |
53 | } | 56 | } |
54 | Command::HelpPrinted => (), | ||
55 | } | 57 | } |
56 | 58 | ||
57 | Ok(()) | 59 | Ok(()) |
@@ -101,11 +103,12 @@ enum Command { | |||
101 | path: PathBuf, | 103 | path: PathBuf, |
102 | op: analysis_bench::Op, | 104 | op: analysis_bench::Op, |
103 | }, | 105 | }, |
104 | HelpPrinted, | ||
105 | } | 106 | } |
106 | 107 | ||
108 | struct HelpPrinted; | ||
109 | |||
107 | impl Command { | 110 | impl Command { |
108 | fn from_args() -> Result<Command> { | 111 | fn from_args() -> Result<Result<Command, HelpPrinted>> { |
109 | let mut matches = Arguments::from_env(); | 112 | let mut matches = Arguments::from_env(); |
110 | let subcommand = matches.subcommand()?.unwrap_or_default(); | 113 | let subcommand = matches.subcommand()?.unwrap_or_default(); |
111 | 114 | ||
@@ -136,7 +139,7 @@ FLAGS: | |||
136 | -h, --help Prints help inforamtion | 139 | -h, --help Prints help inforamtion |
137 | --no-dump" | 140 | --no-dump" |
138 | ); | 141 | ); |
139 | return Ok(Command::HelpPrinted); | 142 | return Ok(Err(HelpPrinted)); |
140 | } | 143 | } |
141 | 144 | ||
142 | let no_dump = matches.contains("--no-dump"); | 145 | let no_dump = matches.contains("--no-dump"); |
@@ -155,7 +158,7 @@ USAGE: | |||
155 | FLAGS: | 158 | FLAGS: |
156 | -h, --help Prints help inforamtion" | 159 | -h, --help Prints help inforamtion" |
157 | ); | 160 | ); |
158 | return Ok(Command::HelpPrinted); | 161 | return Ok(Err(HelpPrinted)); |
159 | } | 162 | } |
160 | 163 | ||
161 | matches.finish().or_else(handle_extra_flags)?; | 164 | matches.finish().or_else(handle_extra_flags)?; |
@@ -175,7 +178,7 @@ FLAGS: | |||
175 | -h, --help Prints help information | 178 | -h, --help Prints help information |
176 | -r, --rainbow" | 179 | -r, --rainbow" |
177 | ); | 180 | ); |
178 | return Ok(Command::HelpPrinted); | 181 | return Ok(Err(HelpPrinted)); |
179 | } | 182 | } |
180 | 183 | ||
181 | let rainbow = matches.contains(["-r", "--rainbow"]); | 184 | let rainbow = matches.contains(["-r", "--rainbow"]); |
@@ -203,7 +206,7 @@ OPTIONS: | |||
203 | ARGS: | 206 | ARGS: |
204 | <PATH>" | 207 | <PATH>" |
205 | ); | 208 | ); |
206 | return Ok(Command::HelpPrinted); | 209 | return Ok(Err(HelpPrinted)); |
207 | } | 210 | } |
208 | 211 | ||
209 | let randomize = matches.contains("--randomize"); | 212 | let randomize = matches.contains("--randomize"); |
@@ -240,7 +243,7 @@ OPTIONS: | |||
240 | ARGS: | 243 | ARGS: |
241 | <PATH> Project to analyse" | 244 | <PATH> Project to analyse" |
242 | ); | 245 | ); |
243 | return Ok(Command::HelpPrinted); | 246 | return Ok(Err(HelpPrinted)); |
244 | } | 247 | } |
245 | 248 | ||
246 | let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default(); | 249 | let path: PathBuf = matches.opt_value_from_str("--path")?.unwrap_or_default(); |
@@ -275,10 +278,10 @@ SUBCOMMANDS: | |||
275 | parse | 278 | parse |
276 | symbols" | 279 | symbols" |
277 | ); | 280 | ); |
278 | return Ok(Command::HelpPrinted); | 281 | return Ok(Err(HelpPrinted)); |
279 | } | 282 | } |
280 | }; | 283 | }; |
281 | Ok(command) | 284 | Ok(Ok(command)) |
282 | } | 285 | } |
283 | } | 286 | } |
284 | 287 | ||