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 <a@4rs.nl>
This commit is contained in:
@@ -49,6 +49,9 @@ Git repository: https://git.4rs.nl/awiteb/n34.git"#;
|
|||||||
/// Footer message, used in the help message
|
/// Footer message, used in the help message
|
||||||
const FOOTER: &str = r#"Please report bugs to <naddr1qqpkuve5qgsqqqqqq9g9uljgjfcyd6dm4fegk8em2yfz0c3qp3tc6mntkrrhawgrqsqqqauesksc39>."#;
|
const FOOTER: &str = r#"Please report bugs to <naddr1qqpkuve5qgsqqqqqq9g9uljgjfcyd6dm4fegk8em2yfz0c3qp3tc6mntkrrhawgrqsqqqauesksc39>."#;
|
||||||
|
|
||||||
|
/// Name of the file storing the repository address
|
||||||
|
pub const NOSTR_ADDRESS_FILE: &str = "nostr-address";
|
||||||
|
|
||||||
/// The command-line interface options
|
/// The command-line interface options
|
||||||
#[derive(Args, Clone)]
|
#[derive(Args, Clone)]
|
||||||
#[clap(
|
#[clap(
|
||||||
|
|||||||
@@ -14,11 +14,13 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://gnu.org/licenses/gpl-3.0.html>.
|
// along with this program. If not, see <https://gnu.org/licenses/gpl-3.0.html>.
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use nostr::{event::EventBuilder, key::PublicKey, types::Url};
|
use nostr::{event::EventBuilder, key::PublicKey, types::Url};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::{CliOptions, CommandRunner},
|
cli::{CliOptions, CommandRunner, NOSTR_ADDRESS_FILE},
|
||||||
error::N34Result,
|
error::N34Result,
|
||||||
nostr_utils::{NostrClient, traits::NewGitRepositoryAnnouncement, utils},
|
nostr_utils::{NostrClient, traits::NewGitRepositoryAnnouncement, utils},
|
||||||
};
|
};
|
||||||
@@ -51,6 +53,10 @@ pub struct AnnounceArgs {
|
|||||||
/// Skip kebab-case validation for the repository ID
|
/// Skip kebab-case validation for the repository ID
|
||||||
#[arg(long)]
|
#[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 {
|
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 nevent = utils::new_nevent(event.id.expect("There is an id"), &write_relays)?;
|
||||||
let naddr = utils::repo_naddr(user_pubk, &options.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
|
client
|
||||||
.send_event_to(event, relays_list.as_ref(), &write_relays)
|
.send_event_to(event, relays_list.as_ref(), &write_relays)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user