From 761344563507eb50726db96f7409a8f3d5928b98 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 10 Feb 2026 12:52:04 +0000 Subject: feat: add ngit account create command Add new 'ngit account create' subcommand to create nostr accounts. This replaces the previous 'signup' command and supports both interactive and non-interactive modes. --- src/bin/ngit/sub_commands/create.rs | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/bin/ngit/sub_commands/create.rs (limited to 'src/bin/ngit/sub_commands/create.rs') diff --git a/src/bin/ngit/sub_commands/create.rs b/src/bin/ngit/sub_commands/create.rs new file mode 100644 index 0000000..e0d89b5 --- /dev/null +++ b/src/bin/ngit/sub_commands/create.rs @@ -0,0 +1,71 @@ +use anyhow::{Context, Result}; +use clap::Parser; +use ngit::client::Params; +use nostr_sdk::ToBech32; + +use crate::{ + cli::Cli, + client::{Client, Connect}, + git::Repo, + login::fresh::signup_non_interactive, +}; + +#[derive(Parser)] +pub struct SubCommandArgs { + /// Display name for the new account + #[arg(long, required = true)] + pub name: String, + + /// Don't publish metadata to relays (offline mode) + #[arg(long)] + pub offline: bool, + + /// Save credentials only to local git config + #[arg(long)] + pub local: bool, +} + +pub async fn launch(_cli: &Cli, args: &SubCommandArgs) -> Result<()> { + let git_repo = Repo::discover().ok(); + + let client = if args.offline { + None + } else { + Some(Client::new(Params::with_git_config_relay_defaults( + &git_repo.as_ref(), + ))) + }; + + let publish = !args.offline; + + let (_signer, public_key, _signer_info, keys) = + signup_non_interactive(args.name.clone(), client.as_ref(), args.local, publish) + .await + .context("failed to create account")?; + + // Display the generated nsec prominently + println!("\n✓ Account created successfully!"); + println!("\nDisplay name: {}", args.name); + println!("Public key (npub): {}", public_key.to_bech32()?); + println!("\n⚠️ IMPORTANT: Save your secret key (nsec) securely!"); + println!("nsec: {}", keys.secret_key().to_bech32()?); + println!("\nYou will need this key to log in from other devices."); + println!("Run 'ngit account export-keys' to see this again.\n"); + + if publish { + println!("✓ Published metadata to relays"); + } + + if args.local { + println!("✓ Saved credentials to local git config only"); + } else { + println!("✓ Saved credentials to global git config"); + } + + // Disconnect client if it was created + if let Some(client) = client { + client.disconnect().await?; + } + + Ok(()) +} -- cgit v1.2.3