summaryrefslogtreecommitdiffstats
path: root/lib/model/folders.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-06 14:50:03 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-06 16:00:04 +0100
commitebf38065f8a0c0c3d1a3a7ce2a4caaaad712432c (patch)
tree00ca89c63f4ce48566202c6c32f76fe1ad3de4d3 /lib/model/folders.go
parent8d3f51e52894d46a4a92a944bc09f4ceaa1abf51 (diff)
Added short project ID name support if not ambiguous.
Diffstat (limited to 'lib/model/folders.go')
-rw-r--r--lib/model/folders.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/model/folders.go b/lib/model/folders.go
index d5ea3bf..b8e6cf5 100644
--- a/lib/model/folders.go
+++ b/lib/model/folders.go
@@ -146,6 +146,27 @@ func (f *Folders) SaveConfig() error {
return foldersConfigWrite(f.fileOnDisk, f.getConfigArrUnsafe())
}
+// ResolveID Complete a Folder ID (helper for user that can use partial ID value)
+func (f *Folders) ResolveID(id string) (string, error) {
+ if id == "" {
+ return "", nil
+ }
+
+ match := []string{}
+ for iid := range f.folders {
+ if strings.HasPrefix(iid, id) {
+ match = append(match, iid)
+ }
+ }
+
+ if len(match) == 1 {
+ return match[0], nil
+ } else if len(match) == 0 {
+ return id, fmt.Errorf("Unknown id")
+ }
+ return id, fmt.Errorf("Multiple IDs found with provided prefix: " + id)
+}
+
// Get returns the folder config or nil if not existing
func (f *Folders) Get(id string) *folder.IFOLDER {
if id == "" {