From f79014235e85554e3661b3f2a02b8fa88bc192ff Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 21 Nov 2024 16:53:17 +0000 Subject: feat(login): overhaul login experience * simplify login menu, making it more accessable to newcomers and easier to select remote signer options * enable `ngit login` to work from anywhere (not just a git repo) * assume fresh login details saved to global git config but fallback to local repository * maintain local repository login via `ngit login --local` * maintain login via CLI arguments eg `ngit send --nsec nsec123` * nudge users to remember nsec when pasting in ncryptsec for a better UX, whilst maintaining the option to be prompted for password everytime * create placeholder menu items for help menu and create account --- src/bin/ngit/cli.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/bin/ngit/cli.rs') diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index d0f934e..b243f70 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs @@ -1,4 +1,6 @@ +use anyhow::{bail, Result}; use clap::{Parser, Subcommand}; +use ngit::login::SignerInfo; use crate::sub_commands; @@ -25,6 +27,30 @@ pub struct Cli { pub disable_cli_spinners: bool, } +pub fn extract_signer_cli_arguments(args: &Cli) -> Result> { + if let Some(nsec) = &args.nsec { + Ok(Some(SignerInfo::Nsec { + nsec: nsec.to_string(), + password: None, + npub: None, + })) + } else if let Some(bunker_uri) = args.bunker_uri.clone() { + if let Some(bunker_app_key) = args.bunker_app_key.clone() { + Ok(Some(SignerInfo::Bunker { + bunker_uri, + bunker_app_key, + npub: None, + })) + } else { + bail!("cli argument bunker-app-key must be supplied when bunker-uri is") + } + } else if args.bunker_app_key.is_some() { + bail!("cli argument bunker-uri must be supplied when bunker-app-key is") + } else { + Ok(None) + } +} + #[derive(Subcommand)] pub enum Commands { /// update cache with latest updates from nostr -- cgit v1.2.3