Skip to content
Permalink
Browse files

Add path for entries and groups commands

  • Loading branch information...
Raggaer committed Mar 18, 2019
1 parent 0066e6f commit 467a7ffd3728a6b885f0841bfd313ee316e29fa4
Showing with 51 additions and 12 deletions.
  1. +8 −8 command.go
  2. +43 −4 entry.go
@@ -52,8 +52,8 @@ var commands = []command{
show(args)
}
},
Help: "Shows an entry (show <entry name|number>)",
HelpSmall: "Shows an entry (show <entry name|number>)",
Help: "Shows an entry (show <entry name|number|entry path>)",
HelpSmall: "Shows an entry (show <entry name|number|entry path>)",
},
{
Key: "xp",
@@ -62,8 +62,8 @@ var commands = []command{
xp(args)
}
},
Help: "Copies an entry password (xp <entry name|number>)",
HelpSmall: "Copies an entry password (xp <entry name|number>)",
Help: "Copies an entry password (xp <entry name|number|entry path>)",
HelpSmall: "Copies an entry password (xp <entry name|number|entry path>)",
},
{
Key: "xw",
@@ -72,8 +72,8 @@ var commands = []command{
xw(args)
}
},
Help: "Copies an entry URL (xw <entry name|number>)",
HelpSmall: "Copies an entry URL (xw <entry name|number>)",
Help: "Copies an entry URL (xw <entry name|number|entry path>)",
HelpSmall: "Copies an entry URL (xw <entry name|number|entry path>)",
},
{
Key: "xu",
@@ -82,8 +82,8 @@ var commands = []command{
xu(args)
}
},
Help: "Copies an entry username (xu <entry name|number>)",
HelpSmall: "Copies an entry username (xu <entry name|number>)",
Help: "Copies an entry username (xu <entry name|number|entry path>)",
HelpSmall: "Copies an entry username (xu <entry name|number|entry path>)",
},
{
Key: "mkdir",
@@ -129,6 +129,45 @@ func getEntryByNameOrId(entry string) *gokeepasslib.Entry {
return &e
}
}

return nil
}

func getEntryByPath(path string) *gokeepasslib.Entry {
// Try to retrieve entry by path
movedPaths := 0
paths := strings.Split(path, "/")
pathRange:
for i, path := range paths {
// If its the entry from the path
if i == len(paths)-1 {
e := getEntryByNameOrId(path)
// Remove moved paths
groupHistory = groupHistory[0 : len(groupHistory)-movedPaths]
return e
}

// Move to next group
gid, err := strconv.Atoi(path)
if err != nil {
for x, g := range currentGroup().Groups {
if strings.ToLower(g.Name) == strings.ToLower(path) {
groupHistory = append(groupHistory, x)
continue pathRange
}
}
} else {
gid--
for x := range currentGroup().Groups {
if x == gid {
groupHistory = append(groupHistory, x)
movedPaths++
continue pathRange
}
}
}
}

return nil
}

@@ -181,7 +220,7 @@ func search(args []string) {

// Command "show" shows information about an entry
func show(args []string) {
entry := getEntryByNameOrId(args[0])
entry := getEntryByPath(args[0])
if entry == nil {
return
}
@@ -280,7 +319,7 @@ func generateEntryPassword(input string) (string, error) {
// Command "xp" copies an entry password
func xp(args []string) {
entry := args[0]
e := getEntryByNameOrId(entry)
e := getEntryByPath(entry)
if e == nil {
return
}
@@ -298,7 +337,7 @@ func xp(args []string) {
// Command "xw" copies an entry URL
func xw(args []string) {
entry := args[0]
e := getEntryByNameOrId(entry)
e := getEntryByPath(entry)
if e == nil {
return
}
@@ -316,7 +355,7 @@ func xw(args []string) {
// Command "xu" copies an entry username
func xu(args []string) {
entry := args[0]
e := getEntryByNameOrId(entry)
e := getEntryByPath(entry)
if e == nil {
return
}

0 comments on commit 467a7ff

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