From 57b48c7368a328be2db8308450233d4559c4e047 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Thu, 22 May 2025 19:17:07 +0000 Subject: [PATCH] feat: Add `--address-file` flag to `repo announce` command This flag creates a file in the current working directory and writes the `naddr` into it. This allows n34 and other tools to recognize the repository address automatically, eliminating the need for manual input by the user. Signed-off-by: Awiteb --- src/cli/mod.rs | 3 +++ src/cli/repo/announce.rs | 31 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index df3b82c..0628b28 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -49,6 +49,9 @@ Git repository: https://git.4rs.nl/awiteb/n34.git"#; /// Footer message, used in the help message const FOOTER: &str = r#"Please report bugs to ."#; +/// Name of the file storing the repository address +pub const NOSTR_ADDRESS_FILE: &str = "nostr-address"; + /// The command-line interface options #[derive(Args, Clone)] #[clap( diff --git a/src/cli/repo/announce.rs b/src/cli/repo/announce.rs index ded490d..2bac9fc 100644 --- a/src/cli/repo/announce.rs +++ b/src/cli/repo/announce.rs @@ -14,11 +14,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::fs; + use clap::Args; use nostr::{event::EventBuilder, key::PublicKey, types::Url}; use crate::{ - cli::{CliOptions, CommandRunner}, + cli::{CliOptions, CommandRunner, NOSTR_ADDRESS_FILE}, error::N34Result, nostr_utils::{NostrClient, traits::NewGitRepositoryAnnouncement, utils}, }; @@ -29,28 +31,32 @@ use crate::{ pub struct AnnounceArgs { /// Unique identifier for the repository in kebab-case. #[arg(long = "id")] - repo_id: String, + repo_id: String, /// A name for the repository. #[arg(short, long)] - name: Option, + name: Option, /// A description for the repository. #[arg(short, long)] - description: Option, + description: Option, /// Webpage URLs for the repository (if provided by the git server). #[arg(short, long)] - web: Vec, + web: Vec, /// URLs for cloning the repository. #[arg(short, long)] - clone: Vec, + clone: Vec, /// Additional maintainers of the repository (besides yourself). #[arg(short, long)] - maintainers: Vec, + maintainers: Vec, /// Labels to categorize the repository. Can be specified multiple times. #[arg(short, long)] - label: Vec, + label: Vec, /// Skip kebab-case validation for the repository ID #[arg(long)] - force_id: bool, + force_id: bool, + /// If set, creates a `nostr-address` file to enable automatic address + /// discovery by n34 + #[arg(long)] + address_file: bool, } impl CommandRunner for AnnounceArgs { @@ -80,6 +86,13 @@ impl CommandRunner for AnnounceArgs { let nevent = utils::new_nevent(event.id.expect("There is an id"), &write_relays)?; let naddr = utils::repo_naddr(user_pubk, &options.relays)?; + + if self.address_file { + let path = std::env::current_dir()?.join(NOSTR_ADDRESS_FILE); + tracing::info!("Create the `nostr-address` file at `{}`", path.display()); + fs::write(path, &naddr)?; + } + client .send_event_to(event, relays_list.as_ref(), &write_relays) .await?;