support_kit/
lib.rs

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
mod args;
mod boilerplate;
mod color;
mod config;
mod deployments;
mod environment;
mod errors;
mod hosts;
mod logs;
mod network;
mod service;
mod shell;
mod structures;
mod support_control;
mod verbosity;

pub use args::*;
pub use boilerplate::*;
pub use color::Color;
pub use config::*;
pub use deployments::*;
pub use environment::Environment;
pub use errors::*;
pub use hosts::*;
pub use logs::*;
pub use network::NetworkConfig;
pub use service::*;
pub use shell::*;
pub use structures::*;
pub use support_control::SupportControl;
pub use verbosity::Verbosity;

type TracingTarget = Box<dyn tracing_subscriber::Layer<tracing_subscriber::Registry> + Send + Sync>;
type TracingTargets = Vec<TracingTarget>;

pub type Result<T> = std::result::Result<T, SupportKitError>;

#[cfg(test)]
mod tests {

    #[test]
    fn usage_as_a_library_consumer() -> Result<(), Box<dyn std::error::Error>> {
        use clap::{Parser, Subcommand};

        #[derive(Parser)]
        struct LocalCli {
            #[clap(subcommand)]
            command: Option<LocalCommand>,

            #[clap(flatten)]
            support: crate::Args,
        }

        #[derive(Clone, Copy, Debug, Subcommand, PartialEq)]
        #[clap(rename_all = "kebab-case")]
        enum LocalCommand {
            DoTheThing,
        }

        let expectations = [
            ("app", None),
            ("app do-the-thing", Some(LocalCommand::DoTheThing)),
            ("app service install", None),
            ("app service start", None),
            ("app service stop", None),
            ("app service uninstall", None),
        ];

        for (input, expected) in expectations {
            let cli = LocalCli::try_parse_from(input.split_whitespace())?;

            assert_eq!(cli.command, expected);
        }

        use crate::{Commands, ServiceCommand::*};
        let expectations = [
            ("app", None),
            ("app do-the-thing", None),
            (
                "app service install",
                Some(Commands::from(Install(Default::default()))),
            ),
            ("app service start", Some(Commands::from(Start))),
            ("app service stop", Some(Commands::from(Stop))),
            ("app service uninstall", Some(Commands::from(Uninstall))),
        ];

        for (input, expected) in expectations {
            let cli = LocalCli::try_parse_from(input.split_whitespace())?;

            assert_eq!(cli.support.command, expected);
        }

        Ok(())
    }
}