From 949c6459aa7683453a7160423b689ceadb08954b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 4 Sep 2024 08:04:48 +0100 Subject: refactor: organise into lib and bin structure the make the code more readable this commit just moves the files, the next commit should fix the imports --- src/bin/ngit/sub_commands/fetch.rs | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/bin/ngit/sub_commands/fetch.rs (limited to 'src/bin/ngit/sub_commands/fetch.rs') diff --git a/src/bin/ngit/sub_commands/fetch.rs b/src/bin/ngit/sub_commands/fetch.rs new file mode 100644 index 0000000..b1e83c5 --- /dev/null +++ b/src/bin/ngit/sub_commands/fetch.rs @@ -0,0 +1,44 @@ +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::{ + cli::Cli, + client::{fetching_with_report, Connect}, + git::{Repo, RepoActions}, + repo_ref::get_repo_coordinates, +}; + +#[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 + }; + fetching_with_report(git_repo.get_path()?, &client, &repo_coordinates).await?; + client.disconnect().await?; + Ok(()) +} -- cgit v1.2.3