Files
MUTN/src/cli/add.go
T

47 lines
1.4 KiB
Go

package cli
import (
"fmt"
"github.com/rwinkhart/MUTN/src/backend"
"os"
)
// AddEntry creates a new entry at targetLocation by taking user input via CLI prompts
// entryType: 0 = standard (password), 1 = auto-generated password, 2 = note
func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
_, isAccessible := backend.TargetIsFile(targetLocation, false, 0)
if isAccessible {
fmt.Println(backend.AnsiError + "Target location already exists" + backend.AnsiReset)
os.Exit(1)
}
var unencryptedEntry []string
if entryType < 2 {
username := input("Username:")
// determine whether to generate the password
var password string
if entryType == 0 {
password = inputHidden("Password:")
} else {
password = backend.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2)
}
totp := inputHidden("TOTP secret:")
url := input("URL:")
if inputBinary("Add a note to this entry?") {
note, _ := editNote([]string{})
unencryptedEntry = append([]string{password, username, totp, url}, note...)
} else {
unencryptedEntry = []string{password, username, totp, url}
}
} else {
note, _ := editNote([]string{})
unencryptedEntry = append([]string{"", "", "", ""}, note...)
}
// write and preview the new entry
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets)
}