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
8 use clap::CommandFactory;
9
10 pub 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
get_help<T: CommandFactory>() -> String17 pub fn get_help<T: CommandFactory>() -> String {
18 let output = <T as CommandFactory>::command().render_help().to_string();
19
20 eprintln!("\n%%% HELP %%%:=====\n{}\n=====\n", output);
21 eprintln!("\n%%% HELP (DEBUG) %%%:=====\n{:?}\n=====\n", output);
22
23 output
24 }
25
get_long_help<T: CommandFactory>() -> String26 pub 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{}\n=====\n", output);
32 eprintln!("\n%%% LONG_HELP (DEBUG) %%%:=====\n{:?}\n=====\n", output);
33
34 output
35 }
36
get_subcommand_long_help<T: CommandFactory>(subcmd: &str) -> String37 pub 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!(
46 "\n%%% SUBCOMMAND `{}` HELP %%%:=====\n{}\n=====\n",
47 subcmd, output
48 );
49 eprintln!(
50 "\n%%% SUBCOMMAND `{}` HELP (DEBUG) %%%:=====\n{:?}\n=====\n",
51 subcmd, output
52 );
53
54 output
55 }
56
57 #[track_caller]
assert_output<P: clap::Parser + std::fmt::Debug>(args: &str, expected: &str, stderr: bool)58 pub fn assert_output<P: clap::Parser + std::fmt::Debug>(args: &str, expected: &str, stderr: bool) {
59 let res = P::try_parse_from(args.split(' ').collect::<Vec<_>>());
60 let err = res.unwrap_err();
61 let actual = err.render().to_string();
62 assert_eq!(
63 stderr,
64 err.use_stderr(),
65 "Should Use STDERR failed. Should be {} but is {}",
66 stderr,
67 err.use_stderr()
68 );
69 snapbox::assert_eq(expected, actual)
70 }
71