diff options
Diffstat (limited to 'src/bin/ngit')
| -rw-r--r-- | src/bin/ngit/cli.rs | 34 | ||||
| -rw-r--r-- | 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; | |||
| 13 | #[command(propagate_version = true)] | 13 | #[command(propagate_version = true)] |
| 14 | pub struct Cli { | 14 | pub struct Cli { |
| 15 | #[command(subcommand)] | 15 | #[command(subcommand)] |
| 16 | pub command: Commands, | 16 | pub command: Option<Commands>, |
| 17 | /// remote signer address | 17 | /// remote signer address |
| 18 | #[arg(long, global = true, hide = true)] | 18 | #[arg(long, global = true, hide = true)] |
| 19 | pub bunker_uri: Option<String>, | 19 | pub bunker_uri: Option<String>, |
| @@ -29,8 +29,40 @@ pub struct Cli { | |||
| 29 | /// disable spinner animations | 29 | /// disable spinner animations |
| 30 | #[arg(long, action, hide = true)] | 30 | #[arg(long, action, hide = true)] |
| 31 | pub disable_cli_spinners: bool, | 31 | pub disable_cli_spinners: bool, |
| 32 | /// show customization options via git config | ||
| 33 | #[arg(short, long, global = true)] | ||
| 34 | pub customize: bool, | ||
| 32 | } | 35 | } |
| 33 | 36 | ||
| 37 | pub const CUSTOMISE_TEMPLATE: &str = r" | ||
| 38 | ========================== | ||
| 39 | Customize ngit | ||
| 40 | ========================== | ||
| 41 | ngit settings are managed through the git config. | ||
| 42 | |||
| 43 | Currently the only settings not not reachable through standard commands relate to default hardcoded relays: | ||
| 44 | |||
| 45 | - nostr.relay-default-set - must have at least 1 value | ||
| 46 | - nostr.relay-blaster-set | ||
| 47 | - nostr.relay-signer-fallback-set | ||
| 48 | |||
| 49 | These take a string of semi-colon separated websocket URLs without spaces. For example: | ||
| 50 | `git config --global nostr.relay-default-set 'wss://relay1.example.com;wss://relay2.example.com'` | ||
| 51 | Or just for this repository: | ||
| 52 | `git config nostr.relay-default-set 'wss://relay1.example.com;wss://relay2.example.com'` | ||
| 53 | |||
| 54 | Other useful settings: | ||
| 55 | - 'nostr.nostate true' to avoid publishing a state event when pushing to a nostr remote. | ||
| 56 | - Login settings configured during `ngit account login`: | ||
| 57 | - nostr.nsec - nsec or ncryptsec | ||
| 58 | - nostr.npub - used for ncryptsec and remote signer | ||
| 59 | - nostr.bunker-uri - used for remote signer | ||
| 60 | - nostr.bunker-app-key - used for remote signer | ||
| 61 | |||
| 62 | Other config settings are applied to the local repository but just for effiency reasons eg nostr.nip05 and nostr.protocol-push | ||
| 63 | ========================== | ||
| 64 | "; | ||
| 65 | |||
| 34 | pub fn extract_signer_cli_arguments(args: &Cli) -> Result<Option<SignerInfo>> { | 66 | pub fn extract_signer_cli_arguments(args: &Cli) -> Result<Option<SignerInfo>> { |
| 35 | if let Some(nsec) = &args.nsec { | 67 | if let Some(nsec) = &args.nsec { |
| 36 | Ok(Some(SignerInfo::Nsec { | 68 | 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 @@ | |||
| 4 | 4 | ||
| 5 | use anyhow::Result; | 5 | use anyhow::Result; |
| 6 | use clap::Parser; | 6 | use clap::Parser; |
| 7 | use cli::{AccountCommands, Cli, Commands}; | 7 | use cli::{AccountCommands, CUSTOMISE_TEMPLATE, Cli, Commands}; |
| 8 | 8 | ||
| 9 | mod cli; | 9 | mod cli; |
| 10 | use ngit::{cli_interactor, client, git, git_events, login, repo_ref}; | 10 | use ngit::{cli_interactor, client, git, git_events, login, repo_ref}; |
| @@ -14,14 +14,28 @@ mod sub_commands; | |||
| 14 | #[tokio::main] | 14 | #[tokio::main] |
| 15 | async fn main() -> Result<()> { | 15 | async fn main() -> Result<()> { |
| 16 | let cli = Cli::parse(); | 16 | let cli = Cli::parse(); |
| 17 | match &cli.command { | 17 | |
| 18 | Commands::Account(args) => match &args.account_command { | 18 | if cli.customize { |
| 19 | AccountCommands::Login(sub_args) => sub_commands::login::launch(&cli, sub_args).await, | 19 | print!("{CUSTOMISE_TEMPLATE}"); |
| 20 | AccountCommands::Logout => sub_commands::logout::launch().await, | 20 | std::process::exit(0); // Exit the program |
| 21 | AccountCommands::ExportKeys => sub_commands::export_keys::launch().await, | 21 | } |
| 22 | }, | 22 | |
| 23 | Commands::Init(args) => sub_commands::init::launch(&cli, args).await, | 23 | if let Some(command) = &cli.command { |
| 24 | Commands::List => sub_commands::list::launch().await, | 24 | match command { |
| 25 | Commands::Send(args) => sub_commands::send::launch(&cli, args, false).await, | 25 | Commands::Account(args) => match &args.account_command { |
| 26 | AccountCommands::Login(sub_args) => { | ||
| 27 | sub_commands::login::launch(&cli, sub_args).await | ||
| 28 | } | ||
| 29 | AccountCommands::Logout => sub_commands::logout::launch().await, | ||
| 30 | AccountCommands::ExportKeys => sub_commands::export_keys::launch().await, | ||
| 31 | }, | ||
| 32 | Commands::Init(args) => sub_commands::init::launch(&cli, args).await, | ||
| 33 | Commands::List => sub_commands::list::launch().await, | ||
| 34 | Commands::Send(args) => sub_commands::send::launch(&cli, args, false).await, | ||
| 35 | } | ||
| 36 | } else { | ||
| 37 | // Handle the case where no command is provided | ||
| 38 | eprintln!("Error: A command must be provided. Use '--help' for more information."); | ||
| 39 | std::process::exit(1); | ||
| 26 | } | 40 | } |
| 27 | } | 41 | } |