From 226909ef16e227206781af4cda17f11e050be498 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Fri, 23 May 2025 12:37:44 +0000 Subject: [PATCH] feat: Read the `nostr-address` file in `issue new` command Signed-off-by: Awiteb --- CHANGELOG.md | 1 + src/cli/issue/new.rs | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3c25a7..3ec663f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `--force-id` flag to bypass case validation in `repo announce` - by Awiteb - Add `--address-file` flag to `repo announce` command - by Awiteb - Read the `nostr-address` file in `repo view` command - by Awiteb +- Read the `nostr-address` file in `issue new` command - by Awiteb ## [0.1.0] - 2025-05-21 diff --git a/src/cli/issue/new.rs b/src/cli/issue/new.rs index 20fd9a2..848c06f 100644 --- a/src/cli/issue/new.rs +++ b/src/cli/issue/new.rs @@ -39,9 +39,11 @@ use crate::{ ) )] pub struct NewArgs { - /// Repository address + /// Repository address in `naddr` format. + /// + /// If not provided, `n34` will look for a `nostr-address` file. #[arg(short, long, value_parser = parsers::repo_naddr)] - naddr: Nip19Coordinate, + naddr: Option, /// Markdown content for the issue. Cannot be used together with the /// `--editor` flag. #[arg(short, long)] @@ -86,26 +88,25 @@ impl CommandRunner for NewArgs { async fn run(self, options: CliOptions) -> N34Result<()> { let client = NostrClient::init(&options).await; let user_pubk = options.pubkey().await?; + let naddr = utils::naddr_or_file(self.naddr.clone(), &utils::nostr_address_path()?)?; + + client.add_relays(&options.relays).await; + client.add_relays(&naddr.relays).await; + let relays_list = client.user_relays_list(user_pubk).await?; let mut write_relays = utils::add_write_relays(options.relays.clone(), relays_list.as_ref()); - client.add_relays(&options.relays).await; - client.add_relays(&self.naddr.relays).await; - write_relays.extend(client.fetch_repo(&self.naddr.coordinate).await?.relays); + write_relays.extend(client.fetch_repo(&naddr.coordinate).await?.relays); let (subject, content) = self.issue_content()?; let content_details = client.parse_content(&content).await; write_relays.extend(content_details.write_relays.clone()); - let event = EventBuilder::new_git_issue( - self.naddr.coordinate.clone(), - content, - subject, - self.label, - )? - .tags(content_details.into_tags()) - .pow(options.pow) - .build(user_pubk); + let event = + EventBuilder::new_git_issue(naddr.coordinate.clone(), content, subject, self.label)? + .tags(content_details.into_tags()) + .pow(options.pow) + .build(user_pubk); let event_id = event.id.expect("There is an id"); tracing::trace!(relays = ?write_relays, "Write relays list");