From 142fee58b0449b3fe3f436986339c318de66b33f Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 15 Jul 2024 17:14:09 +0100 Subject: feat(fetch): fetch events and save to cache enabler to add simplicity, efficency and offline capability to other functions improve repo announcement selection --- src/sub_commands/fetch.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/sub_commands/fetch.rs (limited to 'src/sub_commands/fetch.rs') diff --git a/src/sub_commands/fetch.rs b/src/sub_commands/fetch.rs new file mode 100644 index 0000000..07fd6f9 --- /dev/null +++ b/src/sub_commands/fetch.rs @@ -0,0 +1,46 @@ +use std::collections::HashSet; + +use anyhow::{Context, Result}; +use clap; +use nostr::nips::nip01::Coordinate; + +#[cfg(not(test))] +use crate::client::Client; +#[cfg(test)] +use crate::client::MockConnect; +use crate::{ + client::Connect, + git::{Repo, RepoActions}, + repo_ref::get_repo_coordinates, + Cli, +}; + +#[derive(clap::Args)] +pub struct SubCommandArgs { + /// address pointer to repo announcement + #[arg(long, action)] + repo: Vec, +} + +pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { + let _ = args; + let git_repo = Repo::discover().context("cannot find a git repository")?; + #[cfg(not(test))] + let client = Client::default(); + #[cfg(test)] + let client = ::default(); + let repo_coordinates = if command_args.repo.is_empty() { + get_repo_coordinates(&git_repo, &client).await? + } else { + let mut repo_coordinates = HashSet::new(); + for repo in &command_args.repo { + repo_coordinates.insert(Coordinate::parse(repo.clone())?); + } + repo_coordinates + }; + client + .fetch_all(git_repo.get_path()?, &repo_coordinates) + .await?; + client.disconnect().await?; + Ok(()) +} -- cgit v1.2.3