upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-04 12:29:49 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-11 22:07:48 +0000
commit35ad07180e418931dd499f799d704672d27ff35b (patch)
tree09a06bd72d39bc284ad36523abb5d7f8595d3eed /src/bin
parente07d8bcf3640f16b91f872817939376c7305891a (diff)
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
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/git_remote_nostr/main.rs21
1 files changed, 15 insertions, 6 deletions
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<Option<(NostrUrlDecoded, Repo)>> {
134 let args = env::args(); 134 let args = env::args();
135 let args = args.skip(1).take(2).collect::<Vec<_>>(); 135 let args = args.skip(1).take(2).collect::<Vec<_>>();
136 136
137 let ([_, nostr_remote_url] | [nostr_remote_url]) = args.as_slice() else {
138 bail!("invalid arguments - no url");
139 };
140 let decoded_nostr_url =
141 NostrUrlDecoded::from_str(nostr_remote_url).context("invalid nostr url")?;
142
143 if env::args().nth(1).as_deref() == Some("--version") { 137 if env::args().nth(1).as_deref() == Some("--version") {
144 const VERSION: &str = env!("CARGO_PKG_VERSION"); 138 const VERSION: &str = env!("CARGO_PKG_VERSION");
145 println!("v{VERSION}"); 139 println!("v{VERSION}");
146 return Ok(None); 140 return Ok(None);
147 } 141 }
148 142
143 let ([_, nostr_remote_url] | [nostr_remote_url]) = args.as_slice() else {
144 println!("nostr plugin for git");
145 println!("Usage:");
146 println!(
147 " - add a nostr repository as a remote by using the url format nostr://pub123/identifier"
148 );
149 println!(" - remote branches begining with `pr/` are PRs from contributors");
150 println!(" - to open a PR, push a branch with the prefix `pr/`");
151 println!(" - branches with this prefix are issued by the maintainer(s)");
152 return Ok(None);
153 };
154
155 let decoded_nostr_url =
156 NostrUrlDecoded::from_str(nostr_remote_url).context("invalid nostr url")?;
157
149 let git_repo = Repo::from_path(&PathBuf::from( 158 let git_repo = Repo::from_path(&PathBuf::from(
150 std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?, 159 std::env::var("GIT_DIR").context("git should set GIT_DIR when remote helper is called")?,
151 ))?; 160 ))?;