upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/fetch.rs
blob: c69f1c528904ff21110e743a4bc80e797b6bc727 (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
use std::collections::HashSet;

use anyhow::{Context, Result};
use clap;
use nostr::nips::nip01::Coordinate;

use crate::{
    cli::Cli,
    client::{fetching_with_report, Client, 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<String>,
}

pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> {
    let _ = args;
    let git_repo = Repo::discover().context("cannot find a git repository")?;
    let client = 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(())
}