feat: Make the relays list optional

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-05-24 12:30:40 +00:00
parent de68d61c3f
commit ddea5028ee
5 changed files with 47 additions and 25 deletions

View File

@@ -33,7 +33,7 @@ use self::issue::IssueSubcommands;
use self::reply::ReplyArgs;
use self::repo::RepoSubcommands;
use super::traits::CommandRunner;
use crate::error::N34Result;
use crate::error::{N34Error, N34Result};
/// The command-line interface options
#[derive(Args, Clone)]
@@ -48,8 +48,9 @@ pub struct CliOptions {
/// Your Nostr secret key
#[arg(short, long)]
pub secret_key: Option<SecretKey>,
/// Where your relays list. And repository relays if not included in naddr
#[arg(short, long, required = true)]
/// Fallbacks relay to write and read from it. Multiple relays can be
/// passed.
#[arg(short, long)]
pub relays: Vec<RelayUrl>,
/// Proof of Work difficulty when creatring events
#[arg(long, default_value_t = 0)]
@@ -99,6 +100,14 @@ impl CliOptions {
}
unreachable!("There is no other method until now")
}
/// Returns an error if there are no relays.
pub fn ensure_relays(&self) -> N34Result<()> {
if self.relays.is_empty() {
return Err(N34Error::EmptyRelays);
}
Ok(())
}
}
impl fmt::Debug for CliOptions {