clap/tests/derive/utils.rs
Ed Page 4280fdfcbd fix(help): Replace help writers with renderers
The writer is less convenient and isn't offering any performance
benefits of avoidign the extra allocations, so let's render instead.

This supersedes #3874

Fixes #3873
2022-09-22 09:54:19 -05:00

55 lines
1.4 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} {usage}
{all-args}{after-help}";
pub fn get_help<T: CommandFactory>() -> String {
let output = <T as CommandFactory>::command().render_help().to_string();
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 output = <T as CommandFactory>::command()
.render_long_help()
.to_string();
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 output = <T as CommandFactory>::command()
.get_subcommands_mut()
.find(|s| s.get_name() == subcmd)
.unwrap()
.render_long_help()
.to_string();
eprintln!(
"\n%%% SUBCOMMAND `{}` HELP %%%:=====\n{}\n=====\n",
subcmd, output
);
eprintln!(
"\n%%% SUBCOMMAND `{}` HELP (DEBUG) %%%:=====\n{:?}\n=====\n",
subcmd, output
);
output
}