2020-02-08 22:36:00 +03:00
|
|
|
// 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)]
|
|
|
|
|
2022-02-14 16:09:38 -06:00
|
|
|
use clap::CommandFactory;
|
2020-01-07 15:47:23 +05:30
|
|
|
|
2022-08-31 09:29:00 -05:00
|
|
|
pub const FULL_TEMPLATE: &str = "\
|
|
|
|
{before-help}{name} {version}
|
|
|
|
{author-with-newline}{about-with-newline}
|
|
|
|
{usage-heading}
|
2022-08-31 15:42:59 -05:00
|
|
|
{tab}{usage}
|
2022-08-31 09:29:00 -05:00
|
|
|
|
|
|
|
{all-args}{after-help}";
|
|
|
|
|
2022-02-14 16:09:38 -06:00
|
|
|
pub fn get_help<T: CommandFactory>() -> String {
|
2020-01-07 15:47:23 +05:30
|
|
|
let mut output = Vec::new();
|
2022-02-14 16:09:38 -06:00
|
|
|
<T as CommandFactory>::command()
|
|
|
|
.write_help(&mut output)
|
|
|
|
.unwrap();
|
2020-01-07 15:47:23 +05:30
|
|
|
let output = String::from_utf8(output).unwrap();
|
|
|
|
|
|
|
|
eprintln!("\n%%% HELP %%%:=====\n{}\n=====\n", output);
|
|
|
|
eprintln!("\n%%% HELP (DEBUG) %%%:=====\n{:?}\n=====\n", output);
|
|
|
|
|
|
|
|
output
|
|
|
|
}
|
|
|
|
|
2022-02-14 16:09:38 -06:00
|
|
|
pub fn get_long_help<T: CommandFactory>() -> String {
|
2020-01-07 15:47:23 +05:30
|
|
|
let mut output = Vec::new();
|
2022-02-14 16:09:38 -06:00
|
|
|
<T as CommandFactory>::command()
|
2020-01-07 15:47:23 +05:30
|
|
|
.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
|
|
|
|
}
|
|
|
|
|
2022-02-14 16:09:38 -06:00
|
|
|
pub fn get_subcommand_long_help<T: CommandFactory>(subcmd: &str) -> String {
|
2020-04-12 03:39:13 +02:00
|
|
|
let mut output = Vec::new();
|
2022-02-14 16:09:38 -06:00
|
|
|
<T as CommandFactory>::command()
|
2020-07-06 17:26:53 +03:00
|
|
|
.get_subcommands_mut()
|
|
|
|
.find(|s| s.get_name() == subcmd)
|
2020-04-12 03:39:13 +02:00
|
|
|
.unwrap()
|
|
|
|
.write_long_help(&mut output)
|
|
|
|
.unwrap();
|
|
|
|
let output = String::from_utf8(output).unwrap();
|
2020-01-07 15:47:23 +05:30
|
|
|
|
|
|
|
eprintln!(
|
|
|
|
"\n%%% SUBCOMMAND `{}` HELP %%%:=====\n{}\n=====\n",
|
|
|
|
subcmd, output
|
|
|
|
);
|
|
|
|
eprintln!(
|
|
|
|
"\n%%% SUBCOMMAND `{}` HELP (DEBUG) %%%:=====\n{:?}\n=====\n",
|
|
|
|
subcmd, output
|
|
|
|
);
|
|
|
|
|
|
|
|
output
|
|
|
|
}
|