aboutsummaryrefslogtreecommitdiff
path: root/structopt/tests/utils.rs
blob: c0684a20096fd4718cb88276f7d572cd2548f607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#![allow(unused)]

use structopt::StructOpt;

pub fn get_help<T: StructOpt>() -> String {
    let mut output = Vec::new();
    <T as StructOpt>::clap().write_help(&mut output).unwrap();
    let output = String::from_utf8(output).unwrap();

    eprintln!("\n%%% HELP %%%:=====\n{}\n=====\n", output);
    eprintln!("\n%%% HELP (DEBUG) %%%:=====\n{:?}\n=====\n", output);

    output
}

pub fn get_long_help<T: StructOpt>() -> String {
    let mut output = Vec::new();
    <T as StructOpt>::clap()
        .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
}

pub fn get_subcommand_long_help<T: StructOpt>(subcmd: &str) -> String {
    let output = <T as StructOpt>::clap()
        .get_matches_from_safe(vec!["test", subcmd, "--help"])
        .expect_err("")
        .message;

    eprintln!(
        "\n%%% SUBCOMMAND `{}` HELP %%%:=====\n{}\n=====\n",
        subcmd, output
    );
    eprintln!(
        "\n%%% SUBCOMMAND `{}` HELP (DEBUG) %%%:=====\n{:?}\n=====\n",
        subcmd, output
    );

    output
}