diff options
author | Aleksey Kladov <[email protected]> | 2020-02-16 17:20:22 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-16 17:20:22 +0000 |
commit | 6a3ec2dfa51d92930e028c2ea5af199dbcc813f8 (patch) | |
tree | cd1354a25b5c2144152d4a33802a05000c695fdb /crates | |
parent | 2ba918775cba8d0b1166f7a14a8e114c2fd73f0d (diff) |
Refactor arg parsing
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_cli/src/main.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 749317475..9c23cf001 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -132,18 +132,15 @@ fn main() -> Result<()> { | |||
132 | } | 132 | } |
133 | let verbose = matches.contains(["-v", "--verbose"]); | 133 | let verbose = matches.contains(["-v", "--verbose"]); |
134 | let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); | 134 | let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); |
135 | let highlight_path = matches.opt_value_from_str("--highlight")?; | 135 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; |
136 | let complete_path: Option<String> = matches.opt_value_from_str("--complete")?; | 136 | let complete_path: Option<String> = matches.opt_value_from_str("--complete")?; |
137 | if highlight_path.is_some() && complete_path.is_some() { | 137 | let op = match (highlight_path, complete_path) { |
138 | panic!("either --highlight or --complete must be set, not both") | 138 | (Some(path), None) => { |
139 | } | 139 | let path: String = path; |
140 | let op = if let Some(path) = highlight_path { | 140 | analysis_bench::Op::Highlight { path: path.into() } |
141 | let path: String = path; | 141 | } |
142 | analysis_bench::Op::Highlight { path: path.into() } | 142 | (None, Some(position)) => analysis_bench::Op::Complete(position.parse()?), |
143 | } else if let Some(position) = complete_path { | 143 | _ => panic!("exactly one of `--highlight`, `--complete` must be set"), |
144 | analysis_bench::Op::Complete(position.parse()?) | ||
145 | } else { | ||
146 | panic!("either --highlight or --complete must be set") | ||
147 | }; | 144 | }; |
148 | matches.finish().or_else(handle_extra_flags)?; | 145 | matches.finish().or_else(handle_extra_flags)?; |
149 | analysis_bench::run(verbose, path.as_ref(), op)?; | 146 | analysis_bench::run(verbose, path.as_ref(), op)?; |