summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge/src/cli/disconnect/cli.rs
blob: e13a92506168984f9b0ed4da3e76c041b6cc2d8d (plain)
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
use crate::cli::disconnect::disconnect_bridge::*;
use crate::command::*;
use crate::system_services::service_manager;

const C8Y_CONFIG_FILENAME: &str = "c8y-bridge.conf";
const AZURE_CONFIG_FILENAME: &str = "az-bridge.conf";

#[derive(clap::Subcommand, Debug)]
pub enum TEdgeDisconnectBridgeCli {
    /// Remove bridge connection to Cumulocity.
    C8y,
    /// Remove bridge connection to Azure.
    Az,
}

impl BuildCommand for TEdgeDisconnectBridgeCli {
    fn build_command(self, context: BuildContext) -> Result<Box<dyn Command>, crate::ConfigError> {
        let cmd = match self {
            TEdgeDisconnectBridgeCli::C8y => DisconnectBridgeCommand {
                config_location: context.config_location.clone(),
                config_file: C8Y_CONFIG_FILENAME.into(),
                cloud: Cloud::C8y,
                use_mapper: true,
                use_agent: true,
                service_manager: service_manager(
                    context.user_manager.clone(),
                    context.config_location.tedge_config_root_path,
                )?,
            },
            TEdgeDisconnectBridgeCli::Az => DisconnectBridgeCommand {
                config_location: context.config_location.clone(),
                config_file: AZURE_CONFIG_FILENAME.into(),
                cloud: Cloud::Azure,
                use_mapper: true,
                use_agent: false,
                service_manager: service_manager(
                    context.user_manager.clone(),
                    context.config_location.tedge_config_root_path,
                )?,
            },
        };
        Ok(cmd.into_boxed())
    }
}