seaplane_cli/cli/cmds/metadata/
common.rs

1use clap::{builder::ArgPredicate, Arg, ArgGroup, ArgMatches};
2
3const LONG_DECODE: &str = "Decode the keys and values before printing them
4
5Binary values will be written directly to standard output (which may do strange
6things to your terminal)";
7
8const LONG_HUMAN_READABLE: &str = "Safely decode and truncate output for human readability
9
10Implies --decode-safe --values-width-limit 256";
11
12/// A newtype wrapper to enforce where the ArgMatches came from which reduces errors in checking if
13/// values of arguments were used or not. i.e. `seaplane formation create` may not have the same
14/// arguments as `seaplane account token` even though both produce an `ArgMatches`.
15#[allow(missing_debug_implementations)]
16#[derive(Debug)]
17pub struct SeaplaneMetadataCommonArgMatches<'a>(pub &'a ArgMatches);
18
19pub fn args() -> Vec<Arg> { vec![keys(), base64()] }
20
21pub fn display_args() -> Vec<Arg> {
22    vec![
23        arg!(--("human-readable") - ('H'))
24            .help("Safely decode and truncate output for human readability")
25            .long_help(LONG_HUMAN_READABLE),
26        arg!(--decode - ('D'))
27            .help("Decode the keys and values before printing them")
28            .long_help(LONG_DECODE)
29            .overrides_with_all(["no-decode", "decode-safe"]),
30        arg!(--("decode-safe"))
31            .help("Decode the keys and values in a terminal-friendly way")
32            .overrides_with_all(["decode", "no-decode"]),
33        arg!(--("no-decode"))
34            .help("Print keys and values without decoding them")
35            .overrides_with_all(["decode", "decode-safe"]),
36        arg!(--("no-header") | ("no-heading") | ("no-headers"))
37            .help("Omit the 'KEY' or 'VALUE' heading when printing with `--format=table`"),
38        arg!(--("only-values") | ("only-value")).help("Only print the value"),
39        arg!(--("only-keys") | ("only-key")).help("Only print the key"),
40        arg!(--("keys-width-limit") = ["LIMIT"])
41            .help("Limit the width of the keys when using `--format=table` (0 means unlimited)")
42            .value_parser(clap::value_parser!(usize)),
43        arg!(--("values-width-limit") = ["LIMIT"])
44            .default_value_if("human-readable", ArgPredicate::IsPresent, Some("256"))
45            .help("Limit the width of the values when using `--format=table` (0 means unlimited)")
46            .value_parser(clap::value_parser!(usize)),
47    ]
48}
49
50pub fn base64() -> Arg {
51    arg!(--base64 - ('B')).help("The keys/values are already encoded in URL safe Base64")
52}
53
54pub fn single_key() -> Arg {
55    arg!(key =["KEY"] required ).help("The key of the metadata key-value pair")
56}
57
58pub fn keys() -> Arg {
59    arg!(key =["KEY"]... required ).help("The key(s) of the metadata key-value pair")
60}
61
62pub fn keys_or_values() -> ArgGroup {
63    ArgGroup::new("keys_or_values")
64        .args(["only-keys", "only-values"])
65        .multiple(false)
66        .required(false)
67}