-
Notifications
You must be signed in to change notification settings - Fork 97
/
search.go
60 lines (50 loc) · 1.6 KB
/
search.go
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
// Copyright (c) 2018, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package client
import (
"fmt"
)
// SearchLibrary will search the library for a given query and display results
func SearchLibrary(value string, libraryURL string, authToken string) error {
if len(value) < 3 {
return fmt.Errorf("Bad query '%s'. You must search for at least 3 characters", value)
}
results, err := search(libraryURL, authToken, value)
if err != nil {
return err
}
numEntities := len(results.Entities)
numCollections := len(results.Collections)
numContainers := len(results.Containers)
if numEntities > 0 {
fmt.Printf("Found %d users for '%s'\n", numEntities, value)
for _, ent := range results.Entities {
fmt.Printf("\t%s\n", ent.LibraryURI())
}
fmt.Printf("\n")
} else {
fmt.Printf("No users found for '%s'\n\n", value)
}
if numCollections > 0 {
fmt.Printf("Found %d collections for '%s'\n", numCollections, value)
for _, col := range results.Collections {
fmt.Printf("\t%s\n", col.LibraryURI())
}
fmt.Printf("\n")
} else {
fmt.Printf("No collections found for '%s'\n\n", value)
}
if numContainers > 0 {
fmt.Printf("Found %d containers for '%s'\n", numContainers, value)
for _, con := range results.Containers {
fmt.Printf("\t%s\n", con.LibraryURI())
fmt.Printf("\t\tTags: %s\n", con.TagList())
}
fmt.Printf("\n")
} else {
fmt.Printf("No containers found for '%s'\n\n", value)
}
return nil
}