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
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/ngit/sub_commands/fetch.rs')
-rw-r--r--src/bin/ngit/sub_commands/fetch.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/bin/ngit/sub_commands/fetch.rs b/src/bin/ngit/sub_commands/fetch.rs
new file mode 100644
index 0000000..c69f1c5
--- /dev/null
+++ b/src/bin/ngit/sub_commands/fetch.rs
@@ -0,0 +1,37 @@
1use std::collections::HashSet;
2
3use anyhow::{Context, Result};
4use clap;
5use nostr::nips::nip01::Coordinate;
6
7use crate::{
8 cli::Cli,
9 client::{fetching_with_report, Client, Connect},
10 git::{Repo, RepoActions},
11 repo_ref::get_repo_coordinates,
12};
13
14#[derive(clap::Args)]
15pub struct SubCommandArgs {
16 /// address pointer to repo announcement
17 #[arg(long, action)]
18 repo: Vec<String>,
19}
20
21pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> {
22 let _ = args;
23 let git_repo = Repo::discover().context("cannot find a git repository")?;
24 let client = Client::default();
25 let repo_coordinates = if command_args.repo.is_empty() {
26 get_repo_coordinates(&git_repo, &client).await?
27 } else {
28 let mut repo_coordinates = HashSet::new();
29 for repo in &command_args.repo {
30 repo_coordinates.insert(Coordinate::parse(repo.clone())?);
31 }
32 repo_coordinates
33 };
34 fetching_with_report(git_repo.get_path()?, &client, &repo_coordinates).await?;
35 client.disconnect().await?;
36 Ok(())
37}