1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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(())
}
|