agave_validator/commands/
mod.rs

1pub mod authorized_voter;
2pub mod contact_info;
3pub mod exit;
4pub mod monitor;
5pub mod plugin;
6pub mod repair_shred_from_peer;
7pub mod repair_whitelist;
8pub mod run;
9pub mod set_identity;
10pub mod set_log_filter;
11pub mod set_public_address;
12pub mod staked_nodes_overrides;
13pub mod wait_for_restart_window;
14
15use thiserror::Error;
16
17#[derive(Error, Debug)]
18pub enum Error {
19    #[error("admin rpc error: {0}")]
20    AdminRpc(#[from] jsonrpc_core_client::RpcError),
21
22    #[error(transparent)]
23    Clap(#[from] clap::Error),
24
25    #[error(transparent)]
26    Dynamic(#[from] Box<dyn std::error::Error>),
27
28    #[error(transparent)]
29    Io(#[from] std::io::Error),
30
31    #[error(transparent)]
32    TryFromInt(#[from] std::num::TryFromIntError),
33}
34pub type Result<T> = std::result::Result<T, Error>;
35
36pub trait FromClapArgMatches {
37    fn from_clap_arg_match(matches: &clap::ArgMatches) -> Result<Self>
38    where
39        Self: Sized;
40}
41
42#[cfg(test)]
43pub mod tests {
44    use std::fmt::Debug;
45
46    pub fn verify_args_struct_by_command<T>(app: clap::App, vec: Vec<&str>, expected_arg: T)
47    where
48        T: crate::commands::FromClapArgMatches + PartialEq + Debug,
49    {
50        let matches = app.get_matches_from(vec);
51        let result = T::from_clap_arg_match(&matches);
52        pretty_assertions::assert_eq!(result.unwrap(), expected_arg);
53    }
54
55    pub fn verify_args_struct_by_command_is_error<T>(app: clap::App, vec: Vec<&str>)
56    where
57        T: crate::commands::FromClapArgMatches + PartialEq + Debug,
58    {
59        let matches = app.get_matches_from_safe(vec);
60        assert!(matches.is_err());
61    }
62}