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