|
50 | 50 |
|
51 | 51 | use anyhow::Context as _;
|
52 | 52 |
|
| 53 | +use crate::dump_usage::dump_full_usage_for_readme; |
53 | 54 | use build::Build;
|
54 | 55 | use clap::Parser as _;
|
55 | 56 | use install::Install;
|
56 | 57 | use show::Show;
|
57 | 58 |
|
58 | 59 | mod build;
|
59 | 60 | mod config;
|
| 61 | +mod dump_usage; |
60 | 62 | mod install;
|
61 | 63 | mod install_toolchain;
|
62 | 64 | mod legacy_target_specs;
|
@@ -209,54 +211,6 @@ fn cache_dir() -> anyhow::Result<std::path::PathBuf> {
|
209 | 211 | })
|
210 | 212 | }
|
211 | 213 |
|
212 |
| -/// Convenience function for internal use. Dumps all the CLI usage instructions. Useful for |
213 |
| -/// updating the README. |
214 |
| -fn dump_full_usage_for_readme() -> anyhow::Result<()> { |
215 |
| - use clap::CommandFactory as _; |
216 |
| - let mut command = Cli::command(); |
217 |
| - |
218 |
| - let mut buffer: Vec<u8> = Vec::default(); |
219 |
| - command.build(); |
220 |
| - |
221 |
| - write_help(&mut buffer, &mut command, 0)?; |
222 |
| - user_output!("{}", String::from_utf8(buffer)?); |
223 |
| - |
224 |
| - Ok(()) |
225 |
| -} |
226 |
| - |
227 |
| -/// Recursive function to print the usage instructions for each subcommand. |
228 |
| -fn write_help( |
229 |
| - buffer: &mut impl std::io::Write, |
230 |
| - cmd: &mut clap::Command, |
231 |
| - depth: usize, |
232 |
| -) -> anyhow::Result<()> { |
233 |
| - if cmd.get_name() == "help" { |
234 |
| - return Ok(()); |
235 |
| - } |
236 |
| - |
237 |
| - let mut command = cmd.get_name().to_owned(); |
238 |
| - let indent_depth = if depth == 0 || depth == 1 { 0 } else { depth }; |
239 |
| - let indent = " ".repeat(indent_depth * 4); |
240 |
| - writeln!( |
241 |
| - buffer, |
242 |
| - "\n{}* {}{}", |
243 |
| - indent, |
244 |
| - command.remove(0).to_uppercase(), |
245 |
| - command |
246 |
| - )?; |
247 |
| - |
248 |
| - for line in cmd.render_long_help().to_string().lines() { |
249 |
| - writeln!(buffer, "{indent} {line}")?; |
250 |
| - } |
251 |
| - |
252 |
| - for sub in cmd.get_subcommands_mut() { |
253 |
| - writeln!(buffer)?; |
254 |
| - write_help(buffer, sub, depth + 1)?; |
255 |
| - } |
256 |
| - |
257 |
| - Ok(()) |
258 |
| -} |
259 |
| - |
260 | 214 | /// Returns a string suitable to use as a directory.
|
261 | 215 | ///
|
262 | 216 | /// Created from the spirv-builder source dep and the rustc channel.
|
|
0 commit comments