feat: Support relays and naddrs sets
This commit introduces support for 'sets', a feature that simplifies referencing multiple relays or naddrs with a single word. Sets are stored in the config directory under `n34` as `config.toml` in `TOML` format. The config path follows the `$XDG_CONFIG_HOME` standard, defaulting to `$HOME/.config` if unset. The `n34 sets` command allows managing sets, adding, removing, updating, or displaying them. When using the main `--relays` flag, a set name can be provided to automatically expand its relays (an error occurs if the set contains no relays). Similarly, any command accepting naddrs can reference a set to extract its naddrs. Sets can also be merged by updating a set while specifying another set in `--repo` merges their naddrs, while `--set-relays` merges their relays. Removal follows the same pattern. Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
@@ -21,7 +21,7 @@ use futures::future;
|
||||
use nostr::{event::EventBuilder, key::PublicKey, types::Url};
|
||||
|
||||
use crate::{
|
||||
cli::{CliOptions, CommandRunner, NOSTR_ADDRESS_FILE},
|
||||
cli::{CliConfig, CliOptions, CommandRunner, NOSTR_ADDRESS_FILE, types::RelayOrSetVecExt},
|
||||
error::N34Result,
|
||||
nostr_utils::{NostrClient, traits::NewGitRepositoryAnnouncement, utils},
|
||||
};
|
||||
@@ -81,7 +81,9 @@ impl CommandRunner for AnnounceArgs {
|
||||
async fn run(mut self, options: CliOptions) -> N34Result<()> {
|
||||
options.ensure_relays()?;
|
||||
|
||||
let client = NostrClient::init(&options).await;
|
||||
let config = CliConfig::load_toml(&options.config_path)?;
|
||||
let relays = options.relays.clone().flat_relays(&config.sets)?;
|
||||
let client = NostrClient::init(&options, &relays).await;
|
||||
let user_pubk = options.pubkey().await?;
|
||||
let relays_list = client.user_relays_list(user_pubk).await?;
|
||||
|
||||
@@ -89,14 +91,14 @@ impl CommandRunner for AnnounceArgs {
|
||||
self.maintainers.insert(0, user_pubk);
|
||||
}
|
||||
|
||||
let naddr = utils::repo_naddr(&self.repo_id, user_pubk, &options.relays)?;
|
||||
let naddr = utils::repo_naddr(&self.repo_id, user_pubk, &relays)?;
|
||||
let event = EventBuilder::new_git_repo(
|
||||
self.repo_id,
|
||||
self.name.map(utils::str_trim),
|
||||
self.description.map(utils::str_trim),
|
||||
self.web,
|
||||
self.clone,
|
||||
options.relays.clone(),
|
||||
relays.clone(),
|
||||
self.maintainers.clone(),
|
||||
self.label.into_iter().map(utils::str_trim).collect(),
|
||||
self.force_id,
|
||||
@@ -125,7 +127,7 @@ impl CommandRunner for AnnounceArgs {
|
||||
}
|
||||
|
||||
let write_relays = [
|
||||
options.relays.clone(),
|
||||
relays,
|
||||
utils::add_write_relays(relays_list.as_ref()),
|
||||
// Include read relays for each maintainer (if found)
|
||||
future::join_all(
|
||||
|
||||
Reference in New Issue
Block a user