Skip to content

Commit

Permalink
Add getGroupByPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Raggaer committed Mar 30, 2019
1 parent 75b2f32 commit e44c5d3
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions group.go
Expand Up @@ -118,6 +118,44 @@ func createNewGroup(f *form, input string) {
}
}

func getGroupByPath(path string) *gokeepasslib.Group {
// 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 := currentGroup()
// 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
}

func currentGroup() *gokeepasslib.Group {
g := &database.Content.Root.Groups[0]
for _, h := range groupHistory {
Expand Down

0 comments on commit e44c5d3

Please sign in to comment.