diff options
Diffstat (limited to 'crates/ra_cli/src/main.rs')
-rw-r--r-- | crates/ra_cli/src/main.rs | 116 |
1 files changed, 99 insertions, 17 deletions
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 750cbab86..4a428faff 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | mod load_cargo; | ||
3 | mod analysis_stats; | 4 | mod analysis_stats; |
4 | mod analysis_bench; | 5 | mod analysis_bench; |
5 | mod help; | ||
6 | mod progress_report; | 6 | mod progress_report; |
7 | 7 | ||
8 | use std::{error::Error, fmt::Write, io::Read}; | 8 | use std::{error::Error, fmt::Write, io::Read}; |
@@ -40,21 +40,26 @@ impl Verbosity { | |||
40 | fn main() -> Result<()> { | 40 | fn main() -> Result<()> { |
41 | env_logger::try_init()?; | 41 | env_logger::try_init()?; |
42 | 42 | ||
43 | let subcommand = match std::env::args_os().nth(1) { | 43 | let mut matches = Arguments::from_env(); |
44 | None => { | 44 | let subcommand = matches.subcommand()?.unwrap_or_default(); |
45 | eprintln!("{}", help::GLOBAL_HELP); | ||
46 | return Ok(()); | ||
47 | } | ||
48 | Some(s) => s, | ||
49 | }; | ||
50 | let mut matches = Arguments::from_vec(std::env::args_os().skip(2).collect()); | ||
51 | 45 | ||
52 | match &*subcommand.to_string_lossy() { | 46 | match subcommand.as_str() { |
53 | "parse" => { | 47 | "parse" => { |
54 | if matches.contains(["-h", "--help"]) { | 48 | if matches.contains(["-h", "--help"]) { |
55 | eprintln!("{}", help::PARSE_HELP); | 49 | eprintln!( |
50 | "\ | ||
51 | ra-cli-parse | ||
52 | |||
53 | USAGE: | ||
54 | ra_cli parse [FLAGS] | ||
55 | |||
56 | FLAGS: | ||
57 | -h, --help Prints help inforamtion | ||
58 | --no-dump" | ||
59 | ); | ||
56 | return Ok(()); | 60 | return Ok(()); |
57 | } | 61 | } |
62 | |||
58 | let no_dump = matches.contains("--no-dump"); | 63 | let no_dump = matches.contains("--no-dump"); |
59 | matches.finish().or_else(handle_extra_flags)?; | 64 | matches.finish().or_else(handle_extra_flags)?; |
60 | 65 | ||
@@ -67,10 +72,21 @@ fn main() -> Result<()> { | |||
67 | } | 72 | } |
68 | "symbols" => { | 73 | "symbols" => { |
69 | if matches.contains(["-h", "--help"]) { | 74 | if matches.contains(["-h", "--help"]) { |
70 | eprintln!("{}", help::SYMBOLS_HELP); | 75 | eprintln!( |
76 | "\ | ||
77 | ra-cli-symbols | ||
78 | |||
79 | USAGE: | ||
80 | ra_cli highlight [FLAGS] | ||
81 | |||
82 | FLAGS: | ||
83 | -h, --help Prints help inforamtion" | ||
84 | ); | ||
71 | return Ok(()); | 85 | return Ok(()); |
72 | } | 86 | } |
87 | |||
73 | matches.finish().or_else(handle_extra_flags)?; | 88 | matches.finish().or_else(handle_extra_flags)?; |
89 | |||
74 | let file = file()?; | 90 | let file = file()?; |
75 | for s in file_structure(&file) { | 91 | for s in file_structure(&file) { |
76 | println!("{:?}", s); | 92 | println!("{:?}", s); |
@@ -78,20 +94,51 @@ fn main() -> Result<()> { | |||
78 | } | 94 | } |
79 | "highlight" => { | 95 | "highlight" => { |
80 | if matches.contains(["-h", "--help"]) { | 96 | if matches.contains(["-h", "--help"]) { |
81 | eprintln!("{}", help::HIGHLIGHT_HELP); | 97 | eprintln!( |
98 | "\ | ||
99 | ra-cli-highlight | ||
100 | |||
101 | USAGE: | ||
102 | ra_cli highlight [FLAGS] | ||
103 | |||
104 | FLAGS: | ||
105 | -h, --help Prints help information | ||
106 | -r, --rainbow" | ||
107 | ); | ||
82 | return Ok(()); | 108 | return Ok(()); |
83 | } | 109 | } |
110 | |||
84 | let rainbow_opt = matches.contains(["-r", "--rainbow"]); | 111 | let rainbow_opt = matches.contains(["-r", "--rainbow"]); |
85 | matches.finish().or_else(handle_extra_flags)?; | 112 | matches.finish().or_else(handle_extra_flags)?; |
113 | |||
86 | let (analysis, file_id) = Analysis::from_single_file(read_stdin()?); | 114 | let (analysis, file_id) = Analysis::from_single_file(read_stdin()?); |
87 | let html = analysis.highlight_as_html(file_id, rainbow_opt).unwrap(); | 115 | let html = analysis.highlight_as_html(file_id, rainbow_opt).unwrap(); |
88 | println!("{}", html); | 116 | println!("{}", html); |
89 | } | 117 | } |
90 | "analysis-stats" => { | 118 | "analysis-stats" => { |
91 | if matches.contains(["-h", "--help"]) { | 119 | if matches.contains(["-h", "--help"]) { |
92 | eprintln!("{}", help::ANALYSIS_STATS_HELP); | 120 | eprintln!( |
121 | "\ | ||
122 | ra-cli-analysis-stats | ||
123 | |||
124 | USAGE: | ||
125 | ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] | ||
126 | |||
127 | FLAGS: | ||
128 | -h, --help Prints help information | ||
129 | --memory-usage | ||
130 | -v, --verbose | ||
131 | -q, --quiet | ||
132 | |||
133 | OPTIONS: | ||
134 | -o <ONLY> | ||
135 | |||
136 | ARGS: | ||
137 | <PATH>" | ||
138 | ); | ||
93 | return Ok(()); | 139 | return Ok(()); |
94 | } | 140 | } |
141 | |||
95 | let verbosity = match ( | 142 | let verbosity = match ( |
96 | matches.contains(["-vv", "--spammy"]), | 143 | matches.contains(["-vv", "--spammy"]), |
97 | matches.contains(["-v", "--verbose"]), | 144 | matches.contains(["-v", "--verbose"]), |
@@ -111,11 +158,11 @@ fn main() -> Result<()> { | |||
111 | let path = { | 158 | let path = { |
112 | let mut trailing = matches.free()?; | 159 | let mut trailing = matches.free()?; |
113 | if trailing.len() != 1 { | 160 | if trailing.len() != 1 { |
114 | eprintln!("{}", help::ANALYSIS_STATS_HELP); | ||
115 | Err("Invalid flags")?; | 161 | Err("Invalid flags")?; |
116 | } | 162 | } |
117 | trailing.pop().unwrap() | 163 | trailing.pop().unwrap() |
118 | }; | 164 | }; |
165 | |||
119 | analysis_stats::run( | 166 | analysis_stats::run( |
120 | verbosity, | 167 | verbosity, |
121 | memory_usage, | 168 | memory_usage, |
@@ -127,9 +174,27 @@ fn main() -> Result<()> { | |||
127 | } | 174 | } |
128 | "analysis-bench" => { | 175 | "analysis-bench" => { |
129 | if matches.contains(["-h", "--help"]) { | 176 | if matches.contains(["-h", "--help"]) { |
130 | eprintln!("{}", help::ANALYSIS_BENCH_HELP); | 177 | eprintln!( |
178 | "\ | ||
179 | ra_cli-analysis-bench | ||
180 | |||
181 | USAGE: | ||
182 | ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] | ||
183 | |||
184 | FLAGS: | ||
185 | -h, --help Prints help information | ||
186 | -v, --verbose | ||
187 | |||
188 | OPTIONS: | ||
189 | --complete <PATH:LINE:COLUMN> Compute completions at this location | ||
190 | --highlight <PATH> Hightlight this file | ||
191 | |||
192 | ARGS: | ||
193 | <PATH> Project to analyse" | ||
194 | ); | ||
131 | return Ok(()); | 195 | return Ok(()); |
132 | } | 196 | } |
197 | |||
133 | let verbose = matches.contains(["-v", "--verbose"]); | 198 | let verbose = matches.contains(["-v", "--verbose"]); |
134 | let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); | 199 | let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); |
135 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; | 200 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; |
@@ -144,9 +209,26 @@ fn main() -> Result<()> { | |||
144 | ), | 209 | ), |
145 | }; | 210 | }; |
146 | matches.finish().or_else(handle_extra_flags)?; | 211 | matches.finish().or_else(handle_extra_flags)?; |
212 | |||
147 | analysis_bench::run(verbose, path.as_ref(), op)?; | 213 | analysis_bench::run(verbose, path.as_ref(), op)?; |
148 | } | 214 | } |
149 | _ => eprintln!("{}", help::GLOBAL_HELP), | 215 | _ => eprintln!( |
216 | "\ | ||
217 | ra-cli | ||
218 | |||
219 | USAGE: | ||
220 | ra_cli <SUBCOMMAND> | ||
221 | |||
222 | FLAGS: | ||
223 | -h, --help Prints help information | ||
224 | |||
225 | SUBCOMMANDS: | ||
226 | analysis-bench | ||
227 | analysis-stats | ||
228 | highlight | ||
229 | parse | ||
230 | symbols" | ||
231 | ), | ||
150 | } | 232 | } |
151 | Ok(()) | 233 | Ok(()) |
152 | } | 234 | } |