From 737b7c5728d1688ace4d35a016fbdaed5ffc4e79 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 22 Nov 2024 16:15:57 +0000 Subject: feat(login): `ngit login` use cli args previously cli args were only used during other commands to bypass normal login --- src/bin/ngit/sub_commands/login.rs | 39 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src/bin/ngit/sub_commands') 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}; use clap; use crate::{ - cli::Cli, + cli::{extract_signer_cli_arguments, Cli}, client::{Client, Connect}, git::Repo, login::fresh::fresh_login_or_signup, @@ -19,24 +19,33 @@ pub struct SubCommandArgs { offline: bool, } -pub async fn launch(_args: &Cli, command_args: &SubCommandArgs) -> Result<()> { +pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { // TODO show existing login on record, prompt to logout - // TODO use cli arguments to login - let git_repo_result = Repo::discover().context("cannot find a git repository"); - if command_args.offline { - if let Ok(git_repo) = git_repo_result { - fresh_login_or_signup(&Some(&git_repo), None, command_args.local).await?; - } else { - fresh_login_or_signup(&None, None, command_args.local).await?; - } + let client = if command_args.offline { + None } else { - let client = Client::default(); - if let Ok(git_repo) = git_repo_result { - fresh_login_or_signup(&Some(&git_repo), Some(&client), command_args.local).await?; - } else { - fresh_login_or_signup(&None, Some(&client), command_args.local).await?; + Some(Client::default()) + }; + + let git_repo_result = Repo::discover().context("cannot find a git repository"); + let git_repo_option = { + match git_repo_result { + Ok(git_repo) => Some(git_repo), + Err(_) => None, } + }; + + fresh_login_or_signup( + &git_repo_option.as_ref(), + client.as_ref(), + extract_signer_cli_arguments(args)?, + command_args.local, + ) + .await?; + + // If not offline, disconnect the client + if let Some(client) = client { client.disconnect().await?; } Ok(()) -- cgit v1.2.3