feat: Read the nostr-address file in repo view command

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-05-22 20:45:38 +00:00
parent 55f9b9194e
commit 8ca88804dd
2 changed files with 10 additions and 7 deletions

View File

@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Add `--force-id` flag to bypass case validation in `repo announce` - by Awiteb - 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
## [0.1.0] - 2025-05-21 ## [0.1.0] - 2025-05-21

View File

@@ -22,25 +22,26 @@ use nostr::nips::nip19::Nip19Coordinate;
use crate::{ use crate::{
cli::{CliOptions, CommandRunner, parsers}, cli::{CliOptions, CommandRunner, parsers},
error::N34Result, error::N34Result,
nostr_utils::NostrClient, nostr_utils::{NostrClient, utils},
}; };
/// Arguments for the `repo view` command /// Arguments for the `repo view` command
#[derive(Args, Debug)] #[derive(Args, Debug)]
pub struct ViewArgs { pub struct ViewArgs {
/// Nostr 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)] #[arg(short, long, value_parser = parsers::repo_naddr)]
naddr: Nip19Coordinate, naddr: Option<Nip19Coordinate>,
} }
impl CommandRunner for ViewArgs { impl CommandRunner for ViewArgs {
async fn run(self, options: CliOptions) -> N34Result<()> { async fn run(self, options: CliOptions) -> N34Result<()> {
let naddr = utils::naddr_or_file(self.naddr, &utils::nostr_address_path()?)?;
let client = NostrClient::init(&options).await; let client = NostrClient::init(&options).await;
if !self.naddr.relays.is_empty() { client.add_relays(&naddr.relays).await;
client.add_relays(&self.naddr.relays).await;
}
let repo = client.fetch_repo(&self.naddr.coordinate).await?; let repo = client.fetch_repo(&naddr.coordinate).await?;
let mut msg = format!("ID: {}", repo.id); let mut msg = format!("ID: {}", repo.id);
if let Some(name) = repo.name { if let Some(name) = repo.name {