diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-11 09:06:19 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-11 09:06:19 +0000 |
| commit | f08ee98ab7e19d4e42ffa85aa619f012441fbe47 (patch) | |
| tree | e4d2a15ebeb8a7549ce7e233f4690d71ac95c398 /src/bin/ngit/sub_commands/fetch.rs | |
| parent | 4331b73fbda4831f09a783732d6710012a4dcf20 (diff) | |
Revert "refactor: remove ngit `pull` `push` `fetch`"
This reverts commit 43b5e9b38bf5dcfbac85637a2d3efc69ddfe77ac.
Diffstat (limited to 'src/bin/ngit/sub_commands/fetch.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/fetch.rs | 37 |
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 @@ | |||
| 1 | use std::collections::HashSet; | ||
| 2 | |||
| 3 | use anyhow::{Context, Result}; | ||
| 4 | use clap; | ||
| 5 | use nostr::nips::nip01::Coordinate; | ||
| 6 | |||
| 7 | use 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)] | ||
| 15 | pub struct SubCommandArgs { | ||
| 16 | /// address pointer to repo announcement | ||
| 17 | #[arg(long, action)] | ||
| 18 | repo: Vec<String>, | ||
| 19 | } | ||
| 20 | |||
| 21 | pub 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 | } | ||