From 36de3b05e61130f0c279419edeac8bba534a3791 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 1 Nov 2023 00:00:00 +0000 Subject: refactor(claim) remove setter flow we dont need to th verbose of getters and setters for this right now --- src/sub_commands/claim.rs | 13 +++++------ src/sub_commands/repo_ref.rs | 51 +++++++++++++------------------------------- 2 files changed, 22 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/sub_commands/claim.rs b/src/sub_commands/claim.rs index cb6e99d..9a38f56 100644 --- a/src/sub_commands/claim.rs +++ b/src/sub_commands/claim.rs @@ -67,12 +67,13 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { println!("publishing repostory reference..."); - let repo_event = RepoRef::default() - .set_name(name) - .set_description(description) - .set_root_commit(root_commit.to_string()) - .set_relays(repo_relays.clone()) - .to_event(&keys)?; + let repo_event = RepoRef { + name, + description, + root_commit: root_commit.to_string(), + relays: repo_relays.clone(), + } + .to_event(&keys)?; send_events( &client, diff --git a/src/sub_commands/repo_ref.rs b/src/sub_commands/repo_ref.rs index 82580df..3b0b1b4 100644 --- a/src/sub_commands/repo_ref.rs +++ b/src/sub_commands/repo_ref.rs @@ -3,36 +3,16 @@ use nostr::Tag; #[derive(Default)] pub struct RepoRef { - name: String, - description: String, - root_commit: String, - relays: Vec, + pub name: String, + pub description: String, + pub root_commit: String, + pub relays: Vec, // git_server: String, // other maintainers // code languages and hashtags } impl RepoRef { - pub fn set_name(&mut self, name: String) -> &mut Self { - self.name = name; - self - } - - pub fn set_description(&mut self, description: String) -> &mut Self { - self.description = description; - self - } - - pub fn set_root_commit(&mut self, root_commit: String) -> &mut Self { - self.root_commit = root_commit; - self - } - - pub fn set_relays(&mut self, relays: Vec) -> &mut Self { - self.relays = relays; - self - } - pub fn to_event(&self, keys: &nostr::Keys) -> Result { nostr_sdk::EventBuilder::new( nostr::event::Kind::Custom(30017), @@ -62,22 +42,21 @@ mod tests { use super::*; + fn create() -> nostr::Event { + RepoRef { + name: "test name".to_string(), + description: "test description".to_string(), + root_commit: "23471389461".to_string(), + relays: vec!["ws://relay1.io".to_string(), "ws://relay2.io".to_string()], + } + .to_event(&TEST_KEY_1_KEYS) + .unwrap() + } + mod to_event { use super::*; mod tags { use super::*; - fn create() -> nostr::Event { - RepoRef::default() - .set_name("test name".to_string()) - .set_description("test description".to_string()) - .set_root_commit("23471389461".to_string()) - .set_relays(vec![ - "ws://relay1.io".to_string(), - "ws://relay2.io".to_string(), - ]) - .to_event(&TEST_KEY_1_KEYS) - .unwrap() - } #[test] fn name() { -- cgit v1.2.3