2020-02-08 19:36:00 +00: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 22:09:38 +00:00
|
|
|
use clap::CommandFactory;
|
2020-01-07 10:17:23 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
pub const FULL_TEMPLATE: &str = "\
|
|
|
|
{before-help}{name} {version}
|
|
|
|
{author-with-newline}{about-with-newline}
|
2022-09-07 16:03:55 +00:00
|
|
|
{usage-heading} {usage}
|
2022-08-31 14:29:00 +00:00
|
|
|
|
|
|
|
{all-args}{after-help}";
|
|
|
|
|
2022-02-14 22:09:38 +00:00
|
|
|
pub fn get_help<T: CommandFactory>() -> String {
|
2022-09-22 14:39:24 +00:00
|
|
|
let output = <T as CommandFactory>::command().render_help().to_string();
|
2020-01-07 10:17:23 +00:00
|
|
|
|
2023-01-29 19:14:47 +00:00
|
|
|
eprintln!("\n%%% HELP %%%:=====\n{output}\n=====\n");
|
|
|
|
eprintln!("\n%%% HELP (DEBUG) %%%:=====\n{output:?}\n=====\n");
|
2020-01-07 10:17:23 +00:00
|
|
|
|
|
|
|
output
|
|
|
|
}
|
|
|
|
|
2022-02-14 22:09:38 +00:00
|
|
|
pub fn get_long_help<T: CommandFactory>() -> String {
|
2022-09-22 14:39:24 +00:00
|
|
|
let output = <T as CommandFactory>::command()
|
|
|
|
.render_long_help()
|
|
|
|
.to_string();
|
2020-01-07 10:17:23 +00:00
|
|
|
|
2023-01-29 19:14:47 +00:00
|
|
|
eprintln!("\n%%% LONG_HELP %%%:=====\n{output}\n=====\n");
|
|
|
|
eprintln!("\n%%% LONG_HELP (DEBUG) %%%:=====\n{output:?}\n=====\n");
|
2020-01-07 10:17:23 +00:00
|
|
|
|
|
|
|
output
|
|
|
|
}
|
|
|
|
|
2022-02-14 22:09:38 +00:00
|
|
|
pub fn get_subcommand_long_help<T: CommandFactory>(subcmd: &str) -> String {
|
2022-09-22 14:39:24 +00:00
|
|
|
let output = <T as CommandFactory>::command()
|
2020-07-06 14:26:53 +00:00
|
|
|
.get_subcommands_mut()
|
|
|
|
.find(|s| s.get_name() == subcmd)
|
2020-04-12 01:39:13 +00:00
|
|
|
.unwrap()
|
2022-09-22 14:39:24 +00:00
|
|
|
.render_long_help()
|
|
|
|
.to_string();
|
2020-01-07 10:17:23 +00:00
|
|
|
|
2023-01-29 19:14:47 +00:00
|
|
|
eprintln!("\n%%% SUBCOMMAND `{subcmd}` HELP %%%:=====\n{output}\n=====\n",);
|
|
|
|
eprintln!("\n%%% SUBCOMMAND `{subcmd}` HELP (DEBUG) %%%:=====\n{output:?}\n=====\n",);
|
2020-01-07 10:17:23 +00:00
|
|
|
|
|
|
|
output
|
|
|
|
}
|
2022-09-29 20:56:53 +00:00
|
|
|
|
|
|
|
#[track_caller]
|
|
|
|
pub fn assert_output<P: clap::Parser + std::fmt::Debug>(args: &str, expected: &str, stderr: bool) {
|
|
|
|
let res = P::try_parse_from(args.split(' ').collect::<Vec<_>>());
|
|
|
|
let err = res.unwrap_err();
|
|
|
|
let actual = err.render().to_string();
|
|
|
|
assert_eq!(
|
|
|
|
stderr,
|
|
|
|
err.use_stderr(),
|
|
|
|
"Should Use STDERR failed. Should be {} but is {}",
|
|
|
|
stderr,
|
|
|
|
err.use_stderr()
|
|
|
|
);
|
|
|
|
snapbox::assert_eq(expected, actual)
|
|
|
|
}
|