upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-22 16:15:57 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-22 16:28:14 +0000
commit737b7c5728d1688ace4d35a016fbdaed5ffc4e79 (patch)
tree02f2c472fec31c8e6a848c5dad05104ff39f0247 /src/bin
parentf1b834df4ca8368d7815ccb78e205b15074f23c6 (diff)
feat(login): `ngit login` use cli args
previously cli args were only used during other commands to bypass normal login
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/ngit/sub_commands/login.rs39
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};
2use clap; 2use clap;
3 3
4use crate::{ 4use 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
22pub async fn launch(_args: &Cli, command_args: &SubCommandArgs) -> Result<()> { 22pub 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(())