github.com/apptainer/singularity@v3.1.1+incompatible/pkg/client/library/search.go (about) 1 // Copyright (c) 2018, Sylabs Inc. All rights reserved. 2 // This software is licensed under a 3-clause BSD license. Please consult the 3 // LICENSE.md file distributed with the sources of this project regarding your 4 // rights to use or distribute this software. 5 6 package client 7 8 import ( 9 "fmt" 10 ) 11 12 // SearchLibrary will search the library for a given query and display results 13 func SearchLibrary(value string, libraryURL string, authToken string) error { 14 if len(value) < 3 { 15 return fmt.Errorf("Bad query '%s'. You must search for at least 3 characters", value) 16 } 17 18 results, err := search(libraryURL, authToken, value) 19 if err != nil { 20 return err 21 } 22 23 numEntities := len(results.Entities) 24 numCollections := len(results.Collections) 25 numContainers := len(results.Containers) 26 27 if numEntities > 0 { 28 fmt.Printf("Found %d users for '%s'\n", numEntities, value) 29 for _, ent := range results.Entities { 30 fmt.Printf("\t%s\n", ent.LibraryURI()) 31 } 32 fmt.Printf("\n") 33 } else { 34 fmt.Printf("No users found for '%s'\n\n", value) 35 } 36 37 if numCollections > 0 { 38 fmt.Printf("Found %d collections for '%s'\n", numCollections, value) 39 for _, col := range results.Collections { 40 fmt.Printf("\t%s\n", col.LibraryURI()) 41 } 42 fmt.Printf("\n") 43 } else { 44 fmt.Printf("No collections found for '%s'\n\n", value) 45 } 46 47 if numContainers > 0 { 48 fmt.Printf("Found %d containers for '%s'\n", numContainers, value) 49 for _, con := range results.Containers { 50 fmt.Printf("\t%s\n", con.LibraryURI()) 51 fmt.Printf("\t\tTags: %s\n", con.TagList()) 52 } 53 fmt.Printf("\n") 54 55 } else { 56 fmt.Printf("No containers found for '%s'\n\n", value) 57 } 58 59 return nil 60 }