From 06374fe1fc4c045b70c48ec1941880b30623d557 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Thu, 22 May 2025 07:47:20 +0000
Subject: [PATCH] feat: add `--force-id` flag to bypass case validation in
`repo announce`
The new flag allows users to skip the kebkab case ID check when announcing
repositories.
Signed-off-by: Awiteb
---
CHANGELOG.md | 6 ++++++
src/cli/repo/announce.rs | 4 ++++
src/nostr_utils/traits.rs | 10 +++++++++-
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f7c69c0..cae09c1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Added
+
+- Add `--force-id` flag to bypass case validation in `repo announce` - (Awiteb at [8f627c2](https://git.4rs.nl/awiteb/n34.git/commit/?id=8f627c2704e31538074f06b8300b1a118eb6f21d))
+
## [0.1.0] - 2025-05-21
### Added
diff --git a/src/cli/repo/announce.rs b/src/cli/repo/announce.rs
index 1b487a9..ded490d 100644
--- a/src/cli/repo/announce.rs
+++ b/src/cli/repo/announce.rs
@@ -48,6 +48,9 @@ pub struct AnnounceArgs {
/// Labels to categorize the repository. Can be specified multiple times.
#[arg(short, long)]
label: Vec,
+ /// Skip kebab-case validation for the repository ID
+ #[arg(long)]
+ force_id: bool,
}
impl CommandRunner for AnnounceArgs {
@@ -70,6 +73,7 @@ impl CommandRunner for AnnounceArgs {
options.relays.clone(),
self.maintainers,
self.label.into_iter().map(utils::str_trim).collect(),
+ self.force_id,
)?
.pow(options.pow)
.build(user_pubk);
diff --git a/src/nostr_utils/traits.rs b/src/nostr_utils/traits.rs
index 7abe698..f0fad70 100644
--- a/src/nostr_utils/traits.rs
+++ b/src/nostr_utils/traits.rs
@@ -76,9 +76,17 @@ impl EventBuilder {
relays: Vec,
maintainers: Vec,
labels: Vec,
+ force_id: bool,
) -> N34Result {
let repo_id = repo_id.trim();
- if repo_id.is_empty() || repo_id != repo_id.to_case(Case::Kebab) {
+ let kebab_repo_id = repo_id.to_case(Case::Kebab);
+ if repo_id.is_empty() || (!force_id && repo_id != kebab_repo_id) {
+ if repo_id != kebab_repo_id {
+ tracing::error!(
+ "The repo id should be `{kebab_repo_id}` (kebab-case). Use `--force-id` to \
+ override this check"
+ );
+ }
return Err(N34Error::InvalidRepoId);
}