Standardize some variable names; port to latest libmutton development version

This commit is contained in:
2025-05-31 17:54:12 -04:00
parent 1370f5cd80
commit eda08ad9b6
5 changed files with 25 additions and 25 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ require (
github.com/Trojan2021/BEAN v0.0.0-20241210230804-8f294833b514 github.com/Trojan2021/BEAN v0.0.0-20241210230804-8f294833b514
github.com/charmbracelet/glamour v0.7.0 github.com/charmbracelet/glamour v0.7.0
github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b
github.com/rwinkhart/libmutton v0.3.2-0.20250530043633-6e74e37e5bd2 github.com/rwinkhart/libmutton v0.3.2-0.20250531214811-ca277ba7735d
golang.org/x/term v0.32.0 golang.org/x/term v0.32.0
) )
+2 -2
View File
@@ -61,8 +61,8 @@ github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b h1:ENgsUl
github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b/go.mod h1:cnzIF45I0FCOvE4YIB+26pLCUx2kWyY2llKYZruNaRY= github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b/go.mod h1:cnzIF45I0FCOvE4YIB+26pLCUx2kWyY2llKYZruNaRY=
github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410 h1:NhHwFM3Pgm6zRUfFKvi0p5ndjfFbVWsRwmmhyFlG4PE= github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410 h1:NhHwFM3Pgm6zRUfFKvi0p5ndjfFbVWsRwmmhyFlG4PE=
github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/rwinkhart/libmutton v0.3.2-0.20250530043633-6e74e37e5bd2 h1:XXpL+jd2FLh1XoxaDY0ANgWAHKzf2D6tlbkBSyY+jhg= github.com/rwinkhart/libmutton v0.3.2-0.20250531214811-ca277ba7735d h1:3CdwTMhr7wNn8qmHyyMsT/jPEAB1ebCd4OX58oHrmtA=
github.com/rwinkhart/libmutton v0.3.2-0.20250530043633-6e74e37e5bd2/go.mod h1:uIz4AJcXW7ZHvvoPlLNWQofTBIbFa1UJ2JI6O+FSQ60= github.com/rwinkhart/libmutton v0.3.2-0.20250531214811-ca277ba7735d/go.mod h1:uIz4AJcXW7ZHvvoPlLNWQofTBIbFa1UJ2JI6O+FSQ60=
github.com/rwinkhart/peercred-mini v0.1.0 h1:TiS6u8cEWzW55S9X4iVpU72Iuy/NG6rMUJMtUEVEFLw= github.com/rwinkhart/peercred-mini v0.1.0 h1:TiS6u8cEWzW55S9X4iVpU72Iuy/NG6rMUJMtUEVEFLw=
github.com/rwinkhart/peercred-mini v0.1.0/go.mod h1:+x4Mxc2veE+YePSOpcUasjimh7n799c1KraLuQwHR20= github.com/rwinkhart/peercred-mini v0.1.0/go.mod h1:+x4Mxc2veE+YePSOpcUasjimh7n799c1KraLuQwHR20=
github.com/rwinkhart/rcw v0.2.0 h1:/rFgJ+20OSThipKAX5KPwW2xbPpgh1zl49THmEkkPis= github.com/rwinkhart/rcw v0.2.0 h1:/rFgJ+20OSThipKAX5KPwW2xbPpgh1zl49THmEkkPis=
+5 -5
View File
@@ -15,7 +15,7 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
back.PrintError("Failed to add entry: "+err.Error(), back.ErrorWrite, true) back.PrintError("Failed to add entry: "+err.Error(), back.ErrorWrite, true)
} }
var unencryptedEntry []string var decryptedEntry []string
if entryType < 2 { if entryType < 2 {
username := front.Input("Username:") username := front.Input("Username:")
@@ -32,15 +32,15 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
url := front.Input("URL:") url := front.Input("URL:")
if front.InputBinary("Add a note to this entry?") { if front.InputBinary("Add a note to this entry?") {
note, _ := editNote([]string{}) note, _ := editNote([]string{})
unencryptedEntry = append([]string{password, username, totp, url}, note...) decryptedEntry = append([]string{password, username, totp, url}, note...)
} else { } else {
unencryptedEntry = []string{password, username, totp, url} decryptedEntry = []string{password, username, totp, url}
} }
} else { } else {
note, _ := editNote([]string{}) note, _ := editNote([]string{})
unencryptedEntry = append([]string{"", "", "", ""}, note...) decryptedEntry = append([]string{"", "", "", ""}, note...)
} }
// write and preview the new entry // write and preview the new entry
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets) writeEntryCLI(targetLocation, decryptedEntry, hideSecrets)
} }
+13 -13
View File
@@ -28,7 +28,7 @@ func RenameCli(oldLocationIncomplete string) {
// EditEntryField edits a field of an entry at targetLocation (user input). // EditEntryField edits a field of an entry at targetLocation (user input).
func EditEntryField(targetLocation string, hideSecrets bool, field int) { func EditEntryField(targetLocation string, hideSecrets bool, field int) {
// fetch old entry data (with all required lines present) // fetch old entry data (with all required lines present)
unencryptedEntry, err := core.GetOldEntryData(targetLocation, field) decryptedEntry, err := core.GetOldEntryData(targetLocation, field)
if err != nil { if err != nil {
back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true) back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true)
} }
@@ -36,43 +36,43 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) {
// edit the field // edit the field
switch field { switch field {
case 0: case 0:
unencryptedEntry[field] = string(front.InputHidden("Password:")) decryptedEntry[field] = string(front.InputHidden("Password:"))
case 1: case 1:
unencryptedEntry[field] = front.Input("Username:") decryptedEntry[field] = front.Input("Username:")
case 2: case 2:
unencryptedEntry[field] = string(front.InputHidden("TOTP secret:")) decryptedEntry[field] = string(front.InputHidden("TOTP secret:"))
case 3: case 3:
unencryptedEntry[field] = front.Input("URL:") decryptedEntry[field] = front.Input("URL:")
case 4: // edit notes fields case 4: // edit notes fields
// store note and non-note data separately // store note and non-note data separately
nonNoteData := unencryptedEntry[:4] fieldsMain := decryptedEntry[:4]
noteData := unencryptedEntry[4:] fieldsNote := decryptedEntry[4:]
// edit the note // edit the note
editedNote, noteEdited := editNote(noteData) editedNote, noteEdited := editNote(fieldsNote)
if !noteEdited { // exit early if the note was not edited if !noteEdited { // exit early if the note was not edited
back.PrintError("Entry is unchanged", 0, true) back.PrintError("Entry is unchanged", 0, true)
} }
unencryptedEntry = append(nonNoteData, editedNote...) decryptedEntry = append(fieldsMain, editedNote...)
} }
// write and preview the modified entry // write and preview the modified entry
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets) writeEntryCLI(targetLocation, decryptedEntry, hideSecrets)
} }
// GenUpdate generates a new password for an entry at targetLocation (user input). // GenUpdate generates a new password for an entry at targetLocation (user input).
func GenUpdate(targetLocation string, hideSecrets bool) { func GenUpdate(targetLocation string, hideSecrets bool) {
// fetch old entry data // fetch old entry data
unencryptedEntry, err := core.GetOldEntryData(targetLocation, 0) decryptedEntry, err := core.GetOldEntryData(targetLocation, 0)
if err != nil { if err != nil {
back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true) back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true)
} }
// generate a new password // generate a new password
unencryptedEntry[0] = inputPasswordGen() decryptedEntry[0] = inputPasswordGen()
// write and preview the modified entry // write and preview the modified entry
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets) writeEntryCLI(targetLocation, decryptedEntry, hideSecrets)
} }
// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty). // editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty).
+4 -4
View File
@@ -28,16 +28,16 @@ func inputPasswordGen() string {
} }
// writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied). // writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied).
func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets bool) { func writeEntryCLI(targetLocation string, decryptedEntry []string, hideSecrets bool) {
if core.EntryIsNotEmpty(unencryptedEntry) { if core.EntryIsNotEmpty(decryptedEntry) {
// write the entry to the target location // write the entry to the target location
err := core.WriteEntry(targetLocation, []byte(strings.Join(unencryptedEntry, "\n"))) err := core.WriteEntry(targetLocation, []byte(strings.Join(decryptedEntry, "\n")))
if err != nil { if err != nil {
back.PrintError("Failed to write entry: "+err.Error(), back.ErrorWrite, true) back.PrintError("Failed to write entry: "+err.Error(), back.ErrorWrite, true)
} }
// preview the entry // preview the entry
fmt.Println(back.AnsiBold + "\nEntry Preview:" + back.AnsiReset) fmt.Println(back.AnsiBold + "\nEntry Preview:" + back.AnsiReset)
EntryReader(unencryptedEntry, hideSecrets, true) EntryReader(decryptedEntry, hideSecrets, true)
} else { } else {
back.PrintError("No data supplied for entry", back.ErrorTargetNotFound, true) back.PrintError("No data supplied for entry", back.ErrorTargetNotFound, true)
} }