diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-25 08:07:53 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-25 08:46:58 +0000 |
| commit | 264c6dfe4229cd73bf017f55be0178d596cf06eb (patch) | |
| tree | 46fc35ec5e734a4c1cc914e98c8dbf8939953126 /src/bin/ngit | |
| parent | c6866d621e02205343b175d929785c8a73022806 (diff) | |
feat(login): local login opt with `ngit login`
instead of needing to include the local flag
Diffstat (limited to 'src/bin/ngit')
| -rw-r--r-- | src/bin/ngit/sub_commands/login.rs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs index df45975..1a70118 100644 --- a/src/bin/ngit/sub_commands/login.rs +++ b/src/bin/ngit/sub_commands/login.rs | |||
| @@ -41,7 +41,8 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | |||
| 41 | } | 41 | } |
| 42 | }; | 42 | }; |
| 43 | 43 | ||
| 44 | if logout(git_repo.as_ref(), command_args.local).await? { | 44 | let (logged_out, log_in_locally_only) = logout(git_repo.as_ref(), command_args.local).await?; |
| 45 | if logged_out || log_in_locally_only { | ||
| 45 | fresh_login_or_signup( | 46 | fresh_login_or_signup( |
| 46 | &git_repo.as_ref(), | 47 | &git_repo.as_ref(), |
| 47 | client.as_ref(), | 48 | client.as_ref(), |
| @@ -58,7 +59,8 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | |||
| 58 | Ok(()) | 59 | Ok(()) |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | async fn logout(git_repo: Option<&Repo>, local_only: bool) -> Result<bool> { | 62 | /// return ( bool - logged out, bool - log in to local git locally) |
| 63 | async fn logout(git_repo: Option<&Repo>, local_only: bool) -> Result<(bool, bool)> { | ||
| 62 | for source in if local_only { | 64 | for source in if local_only { |
| 63 | vec![SignerInfoSource::GitLocal] | 65 | vec![SignerInfoSource::GitLocal] |
| 64 | } else { | 66 | } else { |
| @@ -77,12 +79,20 @@ async fn logout(git_repo: Option<&Repo>, local_only: bool) -> Result<bool> { | |||
| 77 | user_ref.metadata.name | 79 | user_ref.metadata.name |
| 78 | ); | 80 | ); |
| 79 | match Interactor::default().choice( | 81 | match Interactor::default().choice( |
| 80 | PromptChoiceParms::default() | 82 | PromptChoiceParms::default().with_default(0).with_choices( |
| 81 | .with_default(0) | 83 | if source == SignerInfoSource::GitGlobal { |
| 82 | .with_choices(vec![ | 84 | vec![ |
| 83 | format!("logout as \"{}\"", user_ref.metadata.name), | 85 | format!("logout as \"{}\"", user_ref.metadata.name), |
| 84 | "remain logged in".to_string(), | 86 | "remain logged in".to_string(), |
| 85 | ]), | 87 | "login to local git repo only as another user".to_string(), |
| 88 | ] | ||
| 89 | } else { | ||
| 90 | vec![ | ||
| 91 | format!("logout as \"{}\"", user_ref.metadata.name), | ||
| 92 | "remain logged in".to_string(), | ||
| 93 | ] | ||
| 94 | }, | ||
| 95 | ), | ||
| 86 | )? { | 96 | )? { |
| 87 | 0 => { | 97 | 0 => { |
| 88 | for item in [ | 98 | for item in [ |
| @@ -101,9 +111,10 @@ async fn logout(git_repo: Option<&Repo>, local_only: bool) -> Result<bool> { | |||
| 101 | )?; | 111 | )?; |
| 102 | } | 112 | } |
| 103 | } | 113 | } |
| 104 | _ => return Ok(false), | 114 | 1 => return Ok((false, local_only)), |
| 115 | _ => return Ok((false, true)), | ||
| 105 | } | 116 | } |
| 106 | } | 117 | } |
| 107 | } | 118 | } |
| 108 | Ok(true) | 119 | Ok((true, local_only)) |
| 109 | } | 120 | } |