From 35ad07180e418931dd499f799d704672d27ff35b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 4 Nov 2024 12:29:49 +0000 Subject: feat(remote): show help when called directly instead of printing an error when `git-remote-nostr` is called directly instead of via plugin, provide some guidance --- src/bin/git_remote_nostr/main.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/bin/git_remote_nostr') diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index f793a0c..ed9fe9d 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs @@ -134,18 +134,27 @@ fn process_args() -> Result> { let args = env::args(); let args = args.skip(1).take(2).collect::>(); - let ([_, nostr_remote_url] | [nostr_remote_url]) = args.as_slice() else { - bail!("invalid arguments - no url"); - }; - let decoded_nostr_url = - NostrUrlDecoded::from_str(nostr_remote_url).context("invalid nostr url")?; - if env::args().nth(1).as_deref() == Some("--version") { const VERSION: &str = env!("CARGO_PKG_VERSION"); println!("v{VERSION}"); return Ok(None); } + let ([_, nostr_remote_url] | [nostr_remote_url]) = args.as_slice() else { + println!("nostr plugin for git"); + println!("Usage:"); + println!( + " - add a nostr repository as a remote by using the url format nostr://pub123/identifier" + ); + println!(" - remote branches begining with `pr/` are PRs from contributors"); + println!(" - to open a PR, push a branch with the prefix `pr/`"); + println!(" - branches with this prefix are issued by the maintainer(s)"); + return Ok(None); + }; + + let decoded_nostr_url = + NostrUrlDecoded::from_str(nostr_remote_url).context("invalid nostr url")?; + let git_repo = Repo::from_path(&PathBuf::from( std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?, ))?; -- cgit v1.2.3