mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -04:00
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/rwinkhart/MUTN/src/offline"
|
|
"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, hidePassword bool, entryType uint8) {
|
|
_, isAccessible := offline.TargetIsFile(targetLocation, false, 0)
|
|
if isAccessible {
|
|
fmt.Println(offline.AnsiError + "Target location already exists" + offline.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 = offline.StringGen(inputInt("Password length:"), inputBinary("Generate a complex (special characters) password?"), 0.2)
|
|
}
|
|
|
|
url := input("URL:")
|
|
if inputBinary("Add a note to this entry?") {
|
|
note, _ := editNote([]string{})
|
|
unencryptedEntry = append([]string{password, username, url}, note...)
|
|
} else {
|
|
unencryptedEntry = []string{password, username, url}
|
|
}
|
|
} else {
|
|
note, _ := editNote([]string{})
|
|
unencryptedEntry = append([]string{"", "", ""}, note...)
|
|
}
|
|
|
|
// write and preview the new entry
|
|
writeEntryShortcut(targetLocation, unencryptedEntry, hidePassword)
|
|
}
|