diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/ngit/sub_commands/create.rs | 71 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/mod.rs | 1 |
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 @@ | |||
| 1 | use anyhow::{Context, Result}; | ||
| 2 | use clap::Parser; | ||
| 3 | use ngit::client::Params; | ||
| 4 | use nostr_sdk::ToBech32; | ||
| 5 | |||
| 6 | use crate::{ | ||
| 7 | cli::Cli, | ||
| 8 | client::{Client, Connect}, | ||
| 9 | git::Repo, | ||
| 10 | login::fresh::signup_non_interactive, | ||
| 11 | }; | ||
| 12 | |||
| 13 | #[derive(Parser)] | ||
| 14 | pub 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 | |||
| 28 | pub 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 @@ | |||
| 1 | pub mod create; | ||
| 1 | pub mod export_keys; | 2 | pub mod export_keys; |
| 2 | pub mod init; | 3 | pub mod init; |
| 3 | pub mod list; | 4 | pub mod list; |