1// Hi, future me (or whoever you are)!
2//
3// Yes, we do need this attr.
4// No, the warnings cannot be fixed otherwise.
5// Accept and endure. Do not touch.
6#![allow(unused)]
7
8use clap::CommandFactory;
9
10pub const FULL_TEMPLATE: &str = "\
11{before-help}{name} {version}
12{author-with-newline}{about-with-newline}
13{usage-heading} {usage}
14
15{all-args}{after-help}";
16
17pub fn get_help<T: CommandFactory>() -> String {
18    let output = <T as CommandFactory>::command().render_help().to_string();
19
20    eprintln!("\n%%% HELP %%%:=====\n{output}\n=====\n");
21    eprintln!("\n%%% HELP (DEBUG) %%%:=====\n{output:?}\n=====\n");
22
23    output
24}
25
26pub fn get_long_help<T: CommandFactory>() -> String {
27    let output = <T as CommandFactory>::command()
28        .render_long_help()
29        .to_string();
30
31    eprintln!("\n%%% LONG_HELP %%%:=====\n{output}\n=====\n");
32    eprintln!("\n%%% LONG_HELP (DEBUG) %%%:=====\n{output:?}\n=====\n");
33
34    output
35}
36
37pub fn get_subcommand_long_help<T: CommandFactory>(subcmd: &str) -> String {
38    let output = <T as CommandFactory>::command()
39        .get_subcommands_mut()
40        .find(|s| s.get_name() == subcmd)
41        .unwrap()
42        .render_long_help()
43        .to_string();
44
45    eprintln!("\n%%% SUBCOMMAND `{subcmd}` HELP %%%:=====\n{output}\n=====\n",);
46    eprintln!("\n%%% SUBCOMMAND `{subcmd}` HELP (DEBUG) %%%:=====\n{output:?}\n=====\n",);
47
48    output
49}
50
51#[track_caller]
52pub fn assert_output<P: clap::Parser + std::fmt::Debug>(args: &str, expected: &str, stderr: bool) {
53    let res = P::try_parse_from(args.split(' ').collect::<Vec<_>>());
54    let err = res.unwrap_err();
55    let actual = err.render().to_string();
56    assert_eq!(
57        stderr,
58        err.use_stderr(),
59        "Should Use STDERR failed. Should be {} but is {}",
60        stderr,
61        err.use_stderr()
62    );
63    snapbox::assert_eq(expected, actual)
64}
65