1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use super::super::{VitInteractiveCommandExec, VitUserInteractionController};
use crate::Result;
use clap::Parser;
use hersir::controller::interactive::args::describe::{
    DescribeNodes, DescribeTopology, DescribeVotePlans, DescribeWallets,
};

#[derive(Parser, Debug)]
pub enum Describe {
    /// Prints available wallets with aliases
    /// that can be used
    Wallets(DescribeWallets),
    /// Prints available node with aliases
    /// that can be used
    Nodes(DescribeNodes),
    /// Prints trusted peer info
    Topology(DescribeTopology),
    /// Prints everything
    All(DescribeAll),
    /// Prints Vit Stations
    Stations(DescribeVitStations),
    /// Prints wallet proxies
    Proxies(DescribeWalletProxies),
    /// Prints Votes Plan
    VotePlan(DescribeVotePlans),
}

impl Describe {
    pub fn exec(&self, command: &mut VitInteractiveCommandExec) -> Result<()> {
        match self {
            Describe::Wallets(wallets) => {
                wallets.exec(command.controller_mut())?;
            }
            Describe::Nodes(desc_nodes) => {
                desc_nodes.exec(command.controller_mut())?;
            }
            Describe::All(all) => {
                all.exec(command)?;
            }
            Describe::Topology(topology) => {
                topology.exec(command.controller_mut())?;
            }
            Describe::VotePlan(vote_plans) => {
                vote_plans.exec(command.controller_mut())?;
            }
            Describe::Stations(stations) => stations.exec(command.vit_controller_mut()),
            Describe::Proxies(proxies) => proxies.exec(command.vit_controller_mut()),
        };
        Ok(())
    }
}

#[derive(Parser, Debug)]
pub struct DescribeVitStations {
    #[clap(short = 'a', long = "alias")]
    pub alias: Option<String>,
}

impl DescribeVitStations {
    pub fn exec(&self, controller: &mut VitUserInteractionController) {
        println!("Vit Stations:");
        for vit_station in controller.vit_stations() {
            println!(
                "\t{}: rest api: {}",
                vit_station.alias(),
                vit_station.address()
            );
        }
    }
}

#[derive(Parser, Debug)]
pub struct DescribeAll {
    #[clap(short = 'a', long = "alias")]
    pub alias: Option<String>,
}

impl DescribeAll {
    pub fn exec(&self, command: &mut VitInteractiveCommandExec) -> Result<()> {
        let describe_wallets = DescribeWallets { alias: None };
        describe_wallets.exec(command.controller_mut())?;
        let describe_nodes = DescribeNodes { alias: None };
        describe_nodes.exec(command.controller_mut())?;
        let describe_wallet_proxies = DescribeWalletProxies { alias: None };
        describe_wallet_proxies.exec(command.vit_controller_mut());
        let describe_vit_stations = DescribeVitStations { alias: None };
        describe_vit_stations.exec(command.vit_controller_mut());
        Ok(())
    }
}

#[derive(Parser, Debug)]
pub struct DescribeWalletProxies {
    #[clap(short = 'a', long = "alias")]
    pub alias: Option<String>,
}

impl DescribeWalletProxies {
    pub fn exec(&self, controller: &mut VitUserInteractionController) {
        println!("Proxies:");
        for proxy in controller.proxies() {
            println!(
                "\t{}: rest api: {}",
                proxy.alias(),
                proxy.settings().proxy_address
            );
        }
    }
}