github.com/apptainer/singularity@v3.1.1+incompatible/cmd/internal/cli/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 cli 7 8 import ( 9 "github.com/spf13/cobra" 10 "github.com/sylabs/singularity/docs" 11 "github.com/sylabs/singularity/internal/pkg/sylog" 12 "github.com/sylabs/singularity/pkg/client/library" 13 ) 14 15 var ( 16 // SearchLibraryURI holds the base URI to a Sylabs library API instance 17 SearchLibraryURI string 18 ) 19 20 func init() { 21 SearchCmd.Flags().SetInterspersed(false) 22 23 SearchCmd.Flags().StringVar(&SearchLibraryURI, "library", "https://library.sylabs.io", "URI for library to search") 24 SearchCmd.Flags().SetAnnotation("library", "envkey", []string{"LIBRARY"}) 25 26 SingularityCmd.AddCommand(SearchCmd) 27 } 28 29 // SearchCmd singularity search 30 var SearchCmd = &cobra.Command{ 31 DisableFlagsInUseLine: true, 32 Args: cobra.ExactArgs(1), 33 PreRun: sylabsToken, 34 Run: func(cmd *cobra.Command, args []string) { 35 if err := client.SearchLibrary(args[0], SearchLibraryURI, authToken); err != nil { 36 sylog.Fatalf("Couldn't search library: %v", err) 37 } 38 39 }, 40 41 Use: docs.SearchUse, 42 Short: docs.SearchShort, 43 Long: docs.SearchLong, 44 Example: docs.SearchExample, 45 }