upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/ngit
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-02-10 12:52:04 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-02-10 13:03:34 +0000
commit761344563507eb50726db96f7409a8f3d5928b98 (patch)
treef5689a4d085b81b4dc8e96fcf7bc8e2693e0b849 /src/bin/ngit
parent6b079f3715611605e348b8709927e0af1675392c (diff)
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.
Diffstat (limited to 'src/bin/ngit')
-rw-r--r--src/bin/ngit/sub_commands/create.rs71
-rw-r--r--src/bin/ngit/sub_commands/mod.rs1
2 files changed, 72 insertions, 0 deletions
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 @@
1use anyhow::{Context, Result};
2use clap::Parser;
3use ngit::client::Params;
4use nostr_sdk::ToBech32;
5
6use crate::{
7 cli::Cli,
8 client::{Client, Connect},
9 git::Repo,
10 login::fresh::signup_non_interactive,
11};
12
13#[derive(Parser)]
14pub struct SubCommandArgs {
15 /// Display name for the new account
16 #[arg(long, required = true)]
17 pub name: String,
18
19 /// Don't publish metadata to relays (offline mode)
20 #[arg(long)]
21 pub offline: bool,
22
23 /// Save credentials only to local git config
24 #[arg(long)]
25 pub local: bool,
26}
27
28pub async fn launch(_cli: &Cli, args: &SubCommandArgs) -> Result<()> {
29 let git_repo = Repo::discover().ok();
30
31 let client = if args.offline {
32 None
33 } else {
34 Some(Client::new(Params::with_git_config_relay_defaults(
35 &git_repo.as_ref(),
36 )))
37 };
38
39 let publish = !args.offline;
40
41 let (_signer, public_key, _signer_info, keys) =
42 signup_non_interactive(args.name.clone(), client.as_ref(), args.local, publish)
43 .await
44 .context("failed to create account")?;
45
46 // Display the generated nsec prominently
47 println!("\n✓ Account created successfully!");
48 println!("\nDisplay name: {}", args.name);
49 println!("Public key (npub): {}", public_key.to_bech32()?);
50 println!("\n⚠️ IMPORTANT: Save your secret key (nsec) securely!");
51 println!("nsec: {}", keys.secret_key().to_bech32()?);
52 println!("\nYou will need this key to log in from other devices.");
53 println!("Run 'ngit account export-keys' to see this again.\n");
54
55 if publish {
56 println!("✓ Published metadata to relays");
57 }
58
59 if args.local {
60 println!("✓ Saved credentials to local git config only");
61 } else {
62 println!("✓ Saved credentials to global git config");
63 }
64
65 // Disconnect client if it was created
66 if let Some(client) = client {
67 client.disconnect().await?;
68 }
69
70 Ok(())
71}
diff --git a/src/bin/ngit/sub_commands/mod.rs b/src/bin/ngit/sub_commands/mod.rs
index b2e7c9a..9c84ef2 100644
--- a/src/bin/ngit/sub_commands/mod.rs
+++ b/src/bin/ngit/sub_commands/mod.rs
@@ -1,3 +1,4 @@
1pub mod create;
1pub mod export_keys; 2pub mod export_keys;
2pub mod init; 3pub mod init;
3pub mod list; 4pub mod list;