This repository was archived by the owner on Oct 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcli.go
More file actions
63 lines (54 loc) · 1.32 KB
/
cli.go
File metadata and controls
63 lines (54 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"fmt"
"github.com/bakape/hydron/common"
"github.com/bakape/hydron/db"
"github.com/bakape/hydron/files"
"github.com/bakape/hydron/tags"
)
// Remove files from the database by ID from the CLI
func removeFiles(ids []string) (err error) {
for _, id := range ids {
err = db.RemoveImage(id)
if err != nil {
return
}
}
return
}
// Add tags to the target file from the CLI
func addTags(sha1 string, tagStr string) error {
id, err := db.GetImageID(sha1)
if err != nil {
return err
}
return db.AddTags(id, tags.FromString(tagStr, common.User))
}
// Remove tags from the target file from the CLI
func removeTags(sha1 string, tagStr string) error {
id, err := db.GetImageID(sha1)
if err != nil {
return err
}
return db.RemoveTags(id, tags.FromString(tagStr, common.User))
}
// Set the target file's name from the CLI
func setImageName(sha1 string, name string) error {
id, err := db.GetImageID(sha1)
if err != nil {
return err
}
return db.SetName(id, name)
}
// Returns file paths that match params and print to console
func searchImages(params string) (err error) {
var page common.Page
err = tags.ParseFilters(params, &page)
if err != nil {
return
}
return db.SearchImages(&page, false, func(i common.CompactImage) error {
fmt.Println(files.SourcePath(i.SHA1, i.Type))
return nil
})
}