use color_eyre::eyre::ContextCompat;
use strum::{EnumDiscriminants, EnumIter, EnumMessage};
mod add_connection;
mod delete_connection;
#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(context = crate::GlobalContext)]
pub struct ConfigCommands {
#[interactive_clap(subcommand)]
config_actions: ConfigActions,
}
#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(context = crate::GlobalContext)]
#[strum_discriminants(derive(EnumMessage, EnumIter))]
#[non_exhaustive]
pub enum ConfigActions {
#[strum_discriminants(strum(
message = "show-connections - Show a list of network connections"
))]
ShowConnections(ShowConnections),
#[strum_discriminants(strum(message = "add-connection - Add a network connection"))]
AddConnection(self::add_connection::AddNetworkConnection),
#[strum_discriminants(strum(
message = "delete-connection - Delete a network connection"
))]
DeleteConnection(self::delete_connection::DeleteNetworkConnection),
}
#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = crate::GlobalContext)]
#[interactive_clap(output_context = ShowConnectionsContext)]
pub struct ShowConnections;
#[derive(Debug, Clone)]
pub struct ShowConnectionsContext;
impl ShowConnectionsContext {
pub fn from_previous_context(
previous_context: crate::GlobalContext,
_scope: &<ShowConnections as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let mut path_config_toml =
dirs::config_dir().wrap_err("Impossible to get your config dir!")?;
path_config_toml.push("unc-cli/config.toml");
eprintln!(
"\nConfiguration data is stored in a file {:?}",
&path_config_toml
);
let config_toml = toml::to_string(&previous_context.config)?;
eprintln!("{}", &config_toml);
Ok(Self)
}
}