From 1982a5c0d653dc13777bc7e5fd735ba64c532ba1 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 7 Mar 2024 12:13:31 -0500 Subject: [PATCH] Do not allow creating empty entries --- src/cli/add.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/cli/add.go b/src/cli/add.go index f9fe7cf..9566b32 100644 --- a/src/cli/add.go +++ b/src/cli/add.go @@ -32,7 +32,21 @@ func AddEntry(targetLocation string, hidePassword bool, isNote bool) { fmt.Println() } - offline.WriteEntry(targetLocation, unencryptedEntry) - fmt.Println(ansiBold + "\nEntry Preview:" + offline.AnsiReset) - EntryReader(unencryptedEntry, hidePassword) + // ensure entry data is not empty + var entryDataPresent bool + for _, line := range unencryptedEntry { + if line != "" { + entryDataPresent = true + break + } + } + + if entryDataPresent { + offline.WriteEntry(targetLocation, unencryptedEntry) + fmt.Println(ansiBold + "\nEntry Preview:" + offline.AnsiReset) + EntryReader(unencryptedEntry, hidePassword) + } else { + fmt.Println(offline.AnsiError + "No data supplied for entry" + offline.AnsiReset) + os.Exit(1) + } }