reactive_graph_client/client/system/remotes/
mod.rs1use std::sync::Arc;
2
3use crate::client::error::CommandError;
4use crate::client::error::CommandError::NoChange;
5use crate::client::result::CommandResult;
6use crate::client::system::remotes::args::RemotesArgs;
7use crate::client::system::remotes::commands::RemotesCommands;
8use reactive_graph_client::ReactiveGraphClient;
9use reactive_graph_table_model::system::instance::InstanceInfos;
10
11pub(crate) mod args;
12pub(crate) mod commands;
13
14pub(crate) async fn remotes(client: &Arc<ReactiveGraphClient>, args: RemotesArgs) -> CommandResult {
15 let Some(command) = args.commands else {
16 return Err(CommandError::MissingSubCommand);
17 };
18 match command {
19 RemotesCommands::List => match client.runtime().remotes().get_all().await {
20 Ok(remotes) => Ok(InstanceInfos::from(remotes).into()),
21 Err(e) => Err(e.into()),
22 },
23 RemotesCommands::Add(address) => {
24 let address = address.into();
25 match client.runtime().remotes().add(&address).await {
26 Ok(remote) => Ok(InstanceInfos::from(remote).into()),
27 Err(e) => Err(e.into()),
28 }
29 }
30 RemotesCommands::Remove(address) => {
31 let address = address.into();
32 match client.runtime().remotes().remove(&address).await {
33 Ok(true) => Ok("Successfully removed remote".into()),
34 Ok(false) => Err(NoChange(format!("Remote {} wasn't removed", &address.base_url()).to_string())),
35 Err(e) => Err(e.into()),
36 }
37 }
38 RemotesCommands::RemoveAll => match client.runtime().remotes().remove_all().await {
39 Ok(true) => Ok("Successfully removed all remotes".into()),
40 Ok(false) => Err(NoChange("No remote was removed".to_string())),
41 Err(e) => Err(e.into()),
42 },
43 RemotesCommands::Update(address) => match client.runtime().remotes().update(&address.into()).await {
44 Ok(remote) => Ok(InstanceInfos::from(remote).into()),
45 Err(e) => Err(e.into()),
46 },
47 RemotesCommands::UpdateAll => match client.runtime().remotes().update_all().await {
48 Ok(remotes) => Ok(InstanceInfos::from(remotes).into()),
49 Err(e) => Err(e.into()),
50 },
51 RemotesCommands::FetchRemotesFromRemote(address) => match client.runtime().remotes().fetch_remotes_from_remote(&address.into()).await {
52 Ok(remotes) => Ok(InstanceInfos::from(remotes).into()),
53 Err(e) => Err(e.into()),
54 },
55 RemotesCommands::FetchRemotesFromAllRemotes => match client.runtime().remotes().fetch_remotes_from_all_remotes().await {
56 Ok(remotes) => Ok(InstanceInfos::from(remotes).into()),
57 Err(e) => Err(e.into()),
58 },
59 }
60}