pact_broker_cli/
cli.rs

1use clap::{Arg, Command, command};
2
3pub mod pact_broker;
4pub mod pact_broker_client;
5pub mod pactflow;
6pub mod pactflow_client;
7pub mod utils;
8
9pub fn build_cli() -> Command {
10    let app = command!()
11        .version(env!("CARGO_PKG_VERSION"))
12        .about("A pact cli tool")
13        .args(add_logging_arguments())
14        .subcommand(
15            pact_broker_client::add_pact_broker_client_command().version(env!("CARGO_PKG_VERSION")),
16        )
17        .subcommand(
18            pactflow_client::add_pactflow_client_command().version(env!("CARGO_PKG_VERSION")),
19        )
20        .subcommand(add_completions_subcommand());
21    app
22}
23
24pub fn add_logging_arguments() -> Vec<Arg> {
25    vec![
26        Arg::new("log-level")
27            .long("log-level")
28            .global(true)
29            .value_name("LEVEL")
30            .help("Set the log level (none, off, error, warn, info, debug, trace)")
31            .value_parser(clap::builder::PossibleValuesParser::new([
32                "off", "none", "error", "warn", "info", "debug", "trace",
33            ]))
34            .default_value("off"),
35    ]
36}
37pub fn add_output_arguments(
38    value_parser_args: Vec<&'static str>,
39    default_value: &'static str,
40) -> Vec<Arg> {
41    vec![
42        Arg::new("output")
43            .short('o')
44            .long("output")
45            .value_name("OUTPUT")
46            .value_parser(clap::builder::PossibleValuesParser::new(&value_parser_args))
47            .default_value(default_value)
48            .value_name("OUTPUT")
49            .help(format!("Value must be one of {:?}", value_parser_args)),
50    ]
51}
52
53pub fn add_ssl_arguments() -> Vec<Arg> {
54    vec![
55        Arg::new("ssl-certificate")
56            .short('c')
57            .long("ssl-certificate")
58            .num_args(1)
59            .help("The path to a valid SSL certificate file")
60            .required(false)
61            .value_name("SSL_CERT_FILE")
62            .env("SSL_CERT_FILE"),
63        Arg::new("skip-ssl-verification")
64            .long("skip-ssl-verification")
65            .num_args(0)
66            .help("Skip SSL certificate verification")
67            .required(false)
68            .value_name("SSL_SKIP_VERIFICATION")
69            .env("SSL_SKIP_VERIFICATION"),
70        Arg::new("ssl-trust-store")
71            .long("ssl-trust-store")
72            .num_args(1)
73            .default_value("true")
74            .value_parser(clap::builder::BoolValueParser::new())
75            .help("Use the system's root trust store for SSL verification")
76            .required(false)
77            .value_name("SSL_TRUST_STORE")
78            .env("SSL_TRUST_STORE"),
79    ]
80}
81
82pub fn add_verbose_arguments() -> Vec<Arg> {
83    vec![
84        Arg::new("verbose")
85            .short('v')
86            .long("verbose")
87            .num_args(0)
88            .help("Verbose output."),
89    ]
90}
91
92fn add_completions_subcommand() -> Command {
93    Command::new("completions") 
94    .about("Generates completion scripts for your shell")
95    .arg(Arg::new("shell")
96        .value_name("SHELL")
97        .required(true)
98        .value_parser(clap::builder::PossibleValuesParser::new(&["bash", "fish", "zsh", "powershell", "elvish"]))
99        .help("The shell to generate the script for"))
100    .arg(Arg::new("dir")
101        .short('d')
102        .long("dir")
103        .value_name("DIRECTORY")
104        .required(false)
105        .default_value(".")
106        .num_args(1)
107        .value_parser(clap::builder::NonEmptyStringValueParser::new())
108        .help("The directory to write the shell completions to, default is the current directory"))
109}