diff options
Diffstat (limited to 'src/bin/ngit')
| -rw-r--r-- | src/bin/ngit/sub_commands/login.rs | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs index bdd215f..390f431 100644 --- a/src/bin/ngit/sub_commands/login.rs +++ b/src/bin/ngit/sub_commands/login.rs | |||
| @@ -2,7 +2,7 @@ use anyhow::{Context, Result}; | |||
| 2 | use clap; | 2 | use clap; |
| 3 | 3 | ||
| 4 | use crate::{ | 4 | use crate::{ |
| 5 | cli::Cli, | 5 | cli::{extract_signer_cli_arguments, Cli}, |
| 6 | client::{Client, Connect}, | 6 | client::{Client, Connect}, |
| 7 | git::Repo, | 7 | git::Repo, |
| 8 | login::fresh::fresh_login_or_signup, | 8 | login::fresh::fresh_login_or_signup, |
| @@ -19,24 +19,33 @@ pub struct SubCommandArgs { | |||
| 19 | offline: bool, | 19 | offline: bool, |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | pub async fn launch(_args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | 22 | pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { |
| 23 | // TODO show existing login on record, prompt to logout | 23 | // TODO show existing login on record, prompt to logout |
| 24 | // TODO use cli arguments to login | ||
| 25 | let git_repo_result = Repo::discover().context("cannot find a git repository"); | ||
| 26 | 24 | ||
| 27 | if command_args.offline { | 25 | let client = if command_args.offline { |
| 28 | if let Ok(git_repo) = git_repo_result { | 26 | None |
| 29 | fresh_login_or_signup(&Some(&git_repo), None, command_args.local).await?; | ||
| 30 | } else { | ||
| 31 | fresh_login_or_signup(&None, None, command_args.local).await?; | ||
| 32 | } | ||
| 33 | } else { | 27 | } else { |
| 34 | let client = Client::default(); | 28 | Some(Client::default()) |
| 35 | if let Ok(git_repo) = git_repo_result { | 29 | }; |
| 36 | fresh_login_or_signup(&Some(&git_repo), Some(&client), command_args.local).await?; | 30 | |
| 37 | } else { | 31 | let git_repo_result = Repo::discover().context("cannot find a git repository"); |
| 38 | fresh_login_or_signup(&None, Some(&client), command_args.local).await?; | 32 | let git_repo_option = { |
| 33 | match git_repo_result { | ||
| 34 | Ok(git_repo) => Some(git_repo), | ||
| 35 | Err(_) => None, | ||
| 39 | } | 36 | } |
| 37 | }; | ||
| 38 | |||
| 39 | fresh_login_or_signup( | ||
| 40 | &git_repo_option.as_ref(), | ||
| 41 | client.as_ref(), | ||
| 42 | extract_signer_cli_arguments(args)?, | ||
| 43 | command_args.local, | ||
| 44 | ) | ||
| 45 | .await?; | ||
| 46 | |||
| 47 | // If not offline, disconnect the client | ||
| 48 | if let Some(client) = client { | ||
| 40 | client.disconnect().await?; | 49 | client.disconnect().await?; |
| 41 | } | 50 | } |
| 42 | Ok(()) | 51 | Ok(()) |