From 0121617bf27ac82cfbd9a25718921ed5f4072d7c Mon Sep 17 00:00:00 2001
From: Jake Taylor <jake@elixxir.io>
Date: Fri, 1 Jul 2022 13:46:40 -0500
Subject: [PATCH] adjust recipient logic for basic cmd executino

---
 cmd/root.go  | 12 ++++++------
 cmd/utils.go |  3 +--
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/cmd/root.go b/cmd/root.go
index 4181ac28c..fc8c0b7b0 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -208,18 +208,18 @@ var rootCmd = &cobra.Command{
 		var recipientContact contact.Contact
 		var recipientID *id.ID
 
+		destFile := viper.GetString("destfile")
 		destId := viper.GetString("destid")
 		sendId := viper.GetString("sendid")
-		if destId == "0" || sendId == destId {
+		if destFile != "" {
+			recipientContact = readContact(destFile)
+			recipientID = recipientContact.ID
+		} else if destId == "0" || sendId == destId {
 			jww.INFO.Printf("Sending message to self")
 			recipientID = receptionIdentity.ID
 			recipientContact = receptionIdentity.GetContact()
-		} else if destId != "0" {
-			recipientContact = readContact()
-			recipientID = parseRecipient(destId)
 		} else {
-			recipientContact = readContact()
-			recipientID = recipientContact.ID
+			recipientID = parseRecipient(destId)
 		}
 		isPrecanPartner := isPrecanID(recipientID)
 
diff --git a/cmd/utils.go b/cmd/utils.go
index aca4fc016..12c01738e 100644
--- a/cmd/utils.go
+++ b/cmd/utils.go
@@ -87,8 +87,7 @@ func writeContact(c contact.Contact) {
 	}
 }
 
-func readContact() contact.Contact {
-	inputFilePath := viper.GetString("destfile")
+func readContact(inputFilePath string) contact.Contact {
 	if inputFilePath == "" {
 		return contact.Contact{}
 	}
-- 
GitLab