diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-19 22:28:15 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-19 22:28:15 +0100 |
| commit | 118d3d86efe155ee6525aba60711e100636a6646 (patch) | |
| tree | 28ec40ed687cd564c8b0dba65333b30fd22af549 /src/sub_commands | |
| parent | 29a093993ce7d0210ac39ceb1a25acc9350492e7 (diff) | |
feat: intergrate `fetch` into `init`
as part of a project to use fetch and the stored cache everywhere
Diffstat (limited to 'src/sub_commands')
| -rw-r--r-- | src/sub_commands/init.rs | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index e46bf74..2a97779 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs | |||
| @@ -11,12 +11,12 @@ use crate::client::Client; | |||
| 11 | use crate::client::MockConnect; | 11 | use crate::client::MockConnect; |
| 12 | use crate::{ | 12 | use crate::{ |
| 13 | cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, | 13 | cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, |
| 14 | client::Connect, | 14 | client::{fetching_with_report, get_repo_ref_from_cache, Connect}, |
| 15 | git::{Repo, RepoActions}, | 15 | git::{Repo, RepoActions}, |
| 16 | login, | 16 | login, |
| 17 | repo_ref::{ | 17 | repo_ref::{ |
| 18 | self, extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, RepoRef, | 18 | extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, |
| 19 | REPO_REF_KIND, | 19 | try_and_get_repo_coordinates, RepoRef, REPO_REF_KIND, |
| 20 | }, | 20 | }, |
| 21 | Cli, | 21 | Cli, |
| 22 | }; | 22 | }; |
| @@ -66,6 +66,21 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 66 | #[cfg(test)] | 66 | #[cfg(test)] |
| 67 | let mut client = <MockConnect as std::default::Default>::default(); | 67 | let mut client = <MockConnect as std::default::Default>::default(); |
| 68 | 68 | ||
| 69 | let repo_coordinates = if let Ok(repo_coordinates) = | ||
| 70 | try_and_get_repo_coordinates(&git_repo, &client, false).await | ||
| 71 | { | ||
| 72 | Some(repo_coordinates) | ||
| 73 | } else { | ||
| 74 | None | ||
| 75 | }; | ||
| 76 | |||
| 77 | let repo_ref = if let Some(repo_coordinates) = repo_coordinates { | ||
| 78 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | ||
| 79 | Some(get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?) | ||
| 80 | } else { | ||
| 81 | None | ||
| 82 | }; | ||
| 83 | |||
| 69 | let (signer, user_ref) = login::launch( | 84 | let (signer, user_ref) = login::launch( |
| 70 | &git_repo, | 85 | &git_repo, |
| 71 | &cli_args.bunker_uri, | 86 | &cli_args.bunker_uri, |
| @@ -77,20 +92,6 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 77 | ) | 92 | ) |
| 78 | .await?; | 93 | .await?; |
| 79 | 94 | ||
| 80 | let repo_ref = if let Ok(rep_ref) = repo_ref::fetch( | ||
| 81 | &git_repo, | ||
| 82 | root_commit.to_string(), | ||
| 83 | &client, | ||
| 84 | user_ref.relays.write(), | ||
| 85 | false, | ||
| 86 | ) | ||
| 87 | .await | ||
| 88 | { | ||
| 89 | Some(rep_ref) | ||
| 90 | } else { | ||
| 91 | None | ||
| 92 | }; | ||
| 93 | |||
| 94 | let repo_config_result = get_repo_config_from_yaml(&git_repo); | 95 | let repo_config_result = get_repo_config_from_yaml(&git_repo); |
| 95 | // TODO: check for other claims | 96 | // TODO: check for other claims |
| 96 | 97 | ||
| @@ -115,7 +116,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 115 | .with_default(if let Some(repo_ref) = &repo_ref { | 116 | .with_default(if let Some(repo_ref) = &repo_ref { |
| 116 | repo_ref.identifier.clone() | 117 | repo_ref.identifier.clone() |
| 117 | } else { | 118 | } else { |
| 118 | name.clone() | 119 | let fallback = name |
| 120 | .clone() | ||
| 119 | .replace(' ', "-") | 121 | .replace(' ', "-") |
| 120 | .chars() | 122 | .chars() |
| 121 | .map(|c| { | 123 | .map(|c| { |
| @@ -125,7 +127,16 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 125 | '-' | 127 | '-' |
| 126 | } | 128 | } |
| 127 | }) | 129 | }) |
| 128 | .collect() | 130 | .collect(); |
| 131 | if let Ok(config) = &repo_config_result { | ||
| 132 | if let Some(identifier) = &config.identifier { | ||
| 133 | identifier.to_string() | ||
| 134 | } else { | ||
| 135 | fallback | ||
| 136 | } | ||
| 137 | } else { | ||
| 138 | fallback | ||
| 139 | } | ||
| 129 | }), | 140 | }), |
| 130 | )?, | 141 | )?, |
| 131 | }; | 142 | }; |