From d0a27fc7828aee5ca7d4c56a9c9f9f5b08878fbf Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 21 May 2025 13:16:25 +0100 Subject: feat: add --customize flag for instructions of how to customise ngit via git config items --- src/bin/ngit/cli.rs | 34 +++++++++++++++++++++++++++++++++- src/bin/ngit/main.rs | 34 ++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index 60bc5d2..5461237 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs @@ -13,7 +13,7 @@ use crate::sub_commands; #[command(propagate_version = true)] pub struct Cli { #[command(subcommand)] - pub command: Commands, + pub command: Option, /// remote signer address #[arg(long, global = true, hide = true)] pub bunker_uri: Option, @@ -29,8 +29,40 @@ pub struct Cli { /// disable spinner animations #[arg(long, action, hide = true)] pub disable_cli_spinners: bool, + /// show customization options via git config + #[arg(short, long, global = true)] + pub customize: bool, } +pub const CUSTOMISE_TEMPLATE: &str = r" +========================== + Customize ngit +========================== +ngit settings are managed through the git config. + +Currently the only settings not not reachable through standard commands relate to default hardcoded relays: + + - nostr.relay-default-set - must have at least 1 value + - nostr.relay-blaster-set + - nostr.relay-signer-fallback-set + +These take a string of semi-colon separated websocket URLs without spaces. For example: +`git config --global nostr.relay-default-set 'wss://relay1.example.com;wss://relay2.example.com'` +Or just for this repository: +`git config nostr.relay-default-set 'wss://relay1.example.com;wss://relay2.example.com'` + +Other useful settings: + - 'nostr.nostate true' to avoid publishing a state event when pushing to a nostr remote. + - Login settings configured during `ngit account login`: + - nostr.nsec - nsec or ncryptsec + - nostr.npub - used for ncryptsec and remote signer + - nostr.bunker-uri - used for remote signer + - nostr.bunker-app-key - used for remote signer + +Other config settings are applied to the local repository but just for effiency reasons eg nostr.nip05 and nostr.protocol-push +========================== +"; + pub fn extract_signer_cli_arguments(args: &Cli) -> Result> { if let Some(nsec) = &args.nsec { Ok(Some(SignerInfo::Nsec { diff --git a/src/bin/ngit/main.rs b/src/bin/ngit/main.rs index a6e3e11..f896e97 100644 --- a/src/bin/ngit/main.rs +++ b/src/bin/ngit/main.rs @@ -4,7 +4,7 @@ use anyhow::Result; use clap::Parser; -use cli::{AccountCommands, Cli, Commands}; +use cli::{AccountCommands, CUSTOMISE_TEMPLATE, Cli, Commands}; mod cli; use ngit::{cli_interactor, client, git, git_events, login, repo_ref}; @@ -14,14 +14,28 @@ mod sub_commands; #[tokio::main] async fn main() -> Result<()> { let cli = Cli::parse(); - match &cli.command { - Commands::Account(args) => match &args.account_command { - AccountCommands::Login(sub_args) => sub_commands::login::launch(&cli, sub_args).await, - AccountCommands::Logout => sub_commands::logout::launch().await, - AccountCommands::ExportKeys => sub_commands::export_keys::launch().await, - }, - Commands::Init(args) => sub_commands::init::launch(&cli, args).await, - Commands::List => sub_commands::list::launch().await, - Commands::Send(args) => sub_commands::send::launch(&cli, args, false).await, + + if cli.customize { + print!("{CUSTOMISE_TEMPLATE}"); + std::process::exit(0); // Exit the program + } + + if let Some(command) = &cli.command { + match command { + Commands::Account(args) => match &args.account_command { + AccountCommands::Login(sub_args) => { + sub_commands::login::launch(&cli, sub_args).await + } + AccountCommands::Logout => sub_commands::logout::launch().await, + AccountCommands::ExportKeys => sub_commands::export_keys::launch().await, + }, + Commands::Init(args) => sub_commands::init::launch(&cli, args).await, + Commands::List => sub_commands::list::launch().await, + Commands::Send(args) => sub_commands::send::launch(&cli, args, false).await, + } + } else { + // Handle the case where no command is provided + eprintln!("Error: A command must be provided. Use '--help' for more information."); + std::process::exit(1); } } -- cgit v1.2.3