Skip to content
Permalink
Browse files

Add entry modification

  • Loading branch information...
Raggaer committed Feb 21, 2019
1 parent ad00145 commit 5c44a49ca57ea2e23c5bff002040a4b1e0131320
Showing with 93 additions and 0 deletions.
  1. +1 −0 README.md
  2. +10 −0 command.go
  3. +82 −0 entry.go
@@ -21,6 +21,7 @@ You can use the `help` command while a database is opened to view the list of co
- `mkdir` Shows and processes a form to create a new group - `mkdir` Shows and processes a form to create a new group
- `rmdir` Removes a group (sends the group to the recycle bin) - `rmdir` Removes a group (sends the group to the recycle bin)
- `new` Shows and processes a form to create a new entry - `new` Shows and processes a form to create a new entry
- `edit` Modifies an entry
- `rm` Removes an entry from the current working group (sends the entry to the recycle bin) - `rm` Removes an entry from the current working group (sends the entry to the recycle bin)
- `show` Shows an entry from the current working group - `show` Shows an entry from the current working group
- `search` Searches entries (by title) from the current working group - `search` Searches entries (by title) from the current working group
@@ -128,6 +128,16 @@ var commands = []command{
Help: "Deletes a group (rmdir <group_name|number>)", Help: "Deletes a group (rmdir <group_name|number>)",
HelpSmall: "Deletes a group (rmdir <group_name|number>)", HelpSmall: "Deletes a group (rmdir <group_name|number>)",
}, },
{
Key: "edit",
Fn: func(args []string) {
if len(args) >= 1 {
edit(args)
}
},
Help: "Edits an entry (edit <path|number>)",
HelpSmall: "Edits an entry (edit <path|number>)",
},
} }


func handleUserInput(input string) { func handleUserInput(input string) {
@@ -20,6 +20,88 @@ type newEntryForm struct {
Username string Username string
} }


type editEntryForm struct {
Id gokeepasslib.UUID
Title string
URL string
Password string
Username string
}

// Command "edit" modifies an entry
func edit(args []string) {
entry := getEntryByNameOrId(args[0])
if entry == nil {
return
}
fmt.Print("- Entry username (" + entry.GetContent("UserName") + "): ")
activeForm = &form{
Fn: editEntry,
Data: &editEntryForm{
Id: entry.UUID,
Title: entry.GetTitle(),
Username: entry.GetContent("UserName"),
URL: entry.GetContent("URL"),
Password: entry.GetPassword(),
},
}
}

func editEntry(f *form, input string) {
data, ok := f.Data.(*editEntryForm)
if !ok {
return
}
switch f.Stage {
case 1:
if input != "" {
data.Username = input
}
fmt.Print("- Entry title (" + data.Title + "): ")
case 2:
if input != "" {
data.Title = input
}
fmt.Print("- Entry password (" + data.Password + "): ")
case 3:
if input != "" {
data.Password = input
}
fmt.Print("- Entry URL (" + data.URL + "): ")
case 4:
if input != "" {
data.URL = input
}
// Update entry based on UUID
g := currentGroup()
for i, e := range g.Entries {
if e.UUID.Compare(data.Id) {
fmt.Printf("Entry '%s' modified\r\n", e.GetTitle())
values := g.Entries[i].Values
for i, v := range values {
if v.Key == "Title" {
values[i].Value.Content = data.Title
}
if v.Key == "URL" {
values[i].Value.Content = data.URL
}
if v.Key == "UserName" {
values[i].Value.Content = data.Username
}
if v.Key == "Password" {
values[i].Value.Content = data.Password
}
}
fmt.Print("Database was changed. Save database? (y/N): ")
activeForm = &form{
Fn: databaseChangedSaveAlert,
}
return
}
}
}
}

func getEntryByNameOrId(entry string) *gokeepasslib.Entry { func getEntryByNameOrId(entry string) *gokeepasslib.Entry {
eid, err := strconv.Atoi(entry) eid, err := strconv.Atoi(entry)
if err != nil { if err != nil {

0 comments on commit 5c44a49

Please sign in to comment.
You can’t perform that action at this time.