agave_validator/commands/contact_info/
mod.rs

1use {
2    crate::{
3        admin_rpc_service,
4        commands::{FromClapArgMatches, Result},
5    },
6    clap::{App, Arg, ArgMatches, SubCommand},
7    solana_cli_output::OutputFormat,
8    std::path::Path,
9};
10
11const COMMAND: &str = "contact-info";
12
13#[derive(Debug, PartialEq)]
14pub struct ContactInfoArgs {
15    pub output: OutputFormat,
16}
17
18impl FromClapArgMatches for ContactInfoArgs {
19    fn from_clap_arg_match(matches: &ArgMatches) -> Result<Self> {
20        Ok(ContactInfoArgs {
21            output: OutputFormat::from_matches(matches, "output", false),
22        })
23    }
24}
25
26pub fn command<'a>() -> App<'a, 'a> {
27    SubCommand::with_name(COMMAND)
28        .about("Display the validator's contact info")
29        .arg(
30            Arg::with_name("output")
31                .long("output")
32                .takes_value(true)
33                .value_name("MODE")
34                .possible_values(&["json", "json-compact"])
35                .help("Output display mode"),
36        )
37}
38
39pub fn execute(matches: &ArgMatches, ledger_path: &Path) -> Result<()> {
40    let contact_info_args = ContactInfoArgs::from_clap_arg_match(matches)?;
41
42    let admin_client = admin_rpc_service::connect(ledger_path);
43    let contact_info = admin_rpc_service::runtime()
44        .block_on(async move { admin_client.await?.contact_info().await })?;
45
46    println!(
47        "{}",
48        contact_info_args.output.formatted_string(&contact_info)
49    );
50
51    Ok(())
52}
53
54#[cfg(test)]
55mod tests {
56    use {
57        super::*,
58        crate::commands::tests::{
59            verify_args_struct_by_command, verify_args_struct_by_command_is_error,
60        },
61    };
62
63    #[test]
64    fn verify_args_struct_by_command_contact_info_output_json() {
65        verify_args_struct_by_command(
66            command(),
67            vec![COMMAND, "--output", "json"],
68            ContactInfoArgs {
69                output: OutputFormat::Json,
70            },
71        );
72    }
73
74    #[test]
75    fn verify_args_struct_by_command_contact_info_output_json_compact() {
76        verify_args_struct_by_command(
77            command(),
78            vec![COMMAND, "--output", "json-compact"],
79            ContactInfoArgs {
80                output: OutputFormat::JsonCompact,
81            },
82        );
83    }
84
85    #[test]
86    fn verify_args_struct_by_command_contact_info_output_default() {
87        verify_args_struct_by_command(
88            command(),
89            vec![COMMAND],
90            ContactInfoArgs {
91                output: OutputFormat::Display,
92            },
93        );
94    }
95
96    #[test]
97    fn verify_args_struct_by_command_contact_info_output_invalid() {
98        verify_args_struct_by_command_is_error::<ContactInfoArgs>(
99            command(),
100            vec![COMMAND, "--output", "invalid_output_type"],
101        );
102    }
103}