clap/tests/derive/utils.rs
Ed Page 439c9e7a91 feat(help): Expose clap's indentation to help_template
This will make it easier for help templates to be consistent with clap
2022-08-31 15:42:59 -05:00

64 lines
1.7 KiB
Rust

// Hi, future me (or whoever you are)!
//
// Yes, we do need this attr.
// No, the warnings cannot be fixed otherwise.
// Accept and endure. Do not touch.
#![allow(unused)]
use clap::CommandFactory;
pub const FULL_TEMPLATE: &str = "\
{before-help}{name} {version}
{author-with-newline}{about-with-newline}
{usage-heading}
{tab}{usage}
{all-args}{after-help}";
pub fn get_help<T: CommandFactory>() -> String {
let mut output = Vec::new();
<T as CommandFactory>::command()
.write_help(&mut output)
.unwrap();
let output = String::from_utf8(output).unwrap();
eprintln!("\n%%% HELP %%%:=====\n{}\n=====\n", output);
eprintln!("\n%%% HELP (DEBUG) %%%:=====\n{:?}\n=====\n", output);
output
}
pub fn get_long_help<T: CommandFactory>() -> String {
let mut output = Vec::new();
<T as CommandFactory>::command()
.write_long_help(&mut output)
.unwrap();
let output = String::from_utf8(output).unwrap();
eprintln!("\n%%% LONG_HELP %%%:=====\n{}\n=====\n", output);
eprintln!("\n%%% LONG_HELP (DEBUG) %%%:=====\n{:?}\n=====\n", output);
output
}
pub fn get_subcommand_long_help<T: CommandFactory>(subcmd: &str) -> String {
let mut output = Vec::new();
<T as CommandFactory>::command()
.get_subcommands_mut()
.find(|s| s.get_name() == subcmd)
.unwrap()
.write_long_help(&mut output)
.unwrap();
let output = String::from_utf8(output).unwrap();
eprintln!(
"\n%%% SUBCOMMAND `{}` HELP %%%:=====\n{}\n=====\n",
subcmd, output
);
eprintln!(
"\n%%% SUBCOMMAND `{}` HELP (DEBUG) %%%:=====\n{:?}\n=====\n",
subcmd, output
);
output
}