diff options
Diffstat (limited to 'src/login.rs')
| -rw-r--r-- | src/login.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/login.rs b/src/login.rs index be358de..19bb97c 100644 --- a/src/login.rs +++ b/src/login.rs | |||
| @@ -25,6 +25,7 @@ use crate::{ | |||
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | /// handles the encrpytion and storage of key material | 27 | /// handles the encrpytion and storage of key material |
| 28 | #[allow(clippy::too_many_arguments)] | ||
| 28 | pub async fn launch( | 29 | pub async fn launch( |
| 29 | git_repo: &Repo, | 30 | git_repo: &Repo, |
| 30 | bunker_uri: &Option<String>, | 31 | bunker_uri: &Option<String>, |
| @@ -34,6 +35,7 @@ pub async fn launch( | |||
| 34 | #[cfg(test)] client: Option<&MockConnect>, | 35 | #[cfg(test)] client: Option<&MockConnect>, |
| 35 | #[cfg(not(test))] client: Option<&Client>, | 36 | #[cfg(not(test))] client: Option<&Client>, |
| 36 | change_user: bool, | 37 | change_user: bool, |
| 38 | silent: bool, | ||
| 37 | ) -> Result<(NostrSigner, UserRef)> { | 39 | ) -> Result<(NostrSigner, UserRef)> { |
| 38 | if let Ok(signer) = match get_signer_without_prompts( | 40 | if let Ok(signer) = match get_signer_without_prompts( |
| 39 | git_repo, | 41 | git_repo, |
| @@ -58,7 +60,8 @@ pub async fn launch( | |||
| 58 | .unwrap_or("unknown ncryptsec".to_string()), | 60 | .unwrap_or("unknown ncryptsec".to_string()), |
| 59 | ) { | 61 | ) { |
| 60 | if let Ok(user_ref) = | 62 | if let Ok(user_ref) = |
| 61 | get_user_details(&public_key, client, git_repo.get_path()?).await | 63 | get_user_details(&public_key, client, git_repo.get_path()?, silent) |
| 64 | .await | ||
| 62 | { | 65 | { |
| 63 | user_ref.metadata.name | 66 | user_ref.metadata.name |
| 64 | } else { | 67 | } else { |
| @@ -94,10 +97,15 @@ pub async fn launch( | |||
| 94 | .context("cannot get public key from signer")?, | 97 | .context("cannot get public key from signer")?, |
| 95 | client, | 98 | client, |
| 96 | git_repo.get_path()?, | 99 | git_repo.get_path()?, |
| 100 | silent, | ||
| 97 | ) | 101 | ) |
| 98 | .await?; | 102 | .await?; |
| 99 | print_logged_in_as(&user_ref, client.is_none())?; | 103 | if !silent { |
| 104 | print_logged_in_as(&user_ref, client.is_none())?; | ||
| 105 | } | ||
| 100 | Ok((signer, user_ref)) | 106 | Ok((signer, user_ref)) |
| 107 | } else if silent { | ||
| 108 | bail!("TODO: enable interactive login in nostr git remote helper"); | ||
| 101 | } else { | 109 | } else { |
| 102 | fresh_login(git_repo, client, change_user).await | 110 | fresh_login(git_repo, client, change_user).await |
| 103 | } | 111 | } |
| @@ -396,7 +404,7 @@ async fn fresh_login( | |||
| 396 | signer.public_key().await? | 404 | signer.public_key().await? |
| 397 | }; | 405 | }; |
| 398 | // lookup profile | 406 | // lookup profile |
| 399 | let user_ref = get_user_details(&public_key, client, git_repo.get_path()?).await?; | 407 | let user_ref = get_user_details(&public_key, client, git_repo.get_path()?, false).await?; |
| 400 | print_logged_in_as(&user_ref, client.is_none())?; | 408 | print_logged_in_as(&user_ref, client.is_none())?; |
| 401 | Ok((signer, user_ref)) | 409 | Ok((signer, user_ref)) |
| 402 | } | 410 | } |
| @@ -612,6 +620,7 @@ async fn get_user_details( | |||
| 612 | #[cfg(test)] client: Option<&crate::client::MockConnect>, | 620 | #[cfg(test)] client: Option<&crate::client::MockConnect>, |
| 613 | #[cfg(not(test))] client: Option<&Client>, | 621 | #[cfg(not(test))] client: Option<&Client>, |
| 614 | git_repo_path: &Path, | 622 | git_repo_path: &Path, |
| 623 | cache_only: bool, | ||
| 615 | ) -> Result<UserRef> { | 624 | ) -> Result<UserRef> { |
| 616 | if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await { | 625 | if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await { |
| 617 | Ok(user_ref) | 626 | Ok(user_ref) |
| @@ -621,8 +630,9 @@ async fn get_user_details( | |||
| 621 | metadata: extract_user_metadata(public_key, &[])?, | 630 | metadata: extract_user_metadata(public_key, &[])?, |
| 622 | relays: extract_user_relays(public_key, &[]), | 631 | relays: extract_user_relays(public_key, &[]), |
| 623 | }; | 632 | }; |
| 624 | 633 | if cache_only { | |
| 625 | if let Some(client) = client { | 634 | Ok(empty) |
| 635 | } else if let Some(client) = client { | ||
| 626 | let term = console::Term::stderr(); | 636 | let term = console::Term::stderr(); |
| 627 | term.write_line("searching for profile...")?; | 637 | term.write_line("searching for profile...")?; |
| 628 | let (_, progress_reporter) = client | 638 | let (_, progress_reporter) = client |