-
Notifications
You must be signed in to change notification settings - Fork 426
/
search.go
45 lines (36 loc) · 1.31 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
// 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 cli
import (
"github.com/spf13/cobra"
"github.com/sylabs/singularity/internal/pkg/sylog"
"github.com/sylabs/singularity/pkg/client/library"
"github.com/sylabs/singularity/src/docs"
)
var (
// SearchLibraryURI holds the base URI to a Sylabs library API instance
SearchLibraryURI string
)
func init() {
SearchCmd.Flags().SetInterspersed(false)
SearchCmd.Flags().StringVar(&SearchLibraryURI, "library", "https://library.sylabs.io", "URI for library to search")
SearchCmd.Flags().SetAnnotation("library", "envkey", []string{"LIBRARY"})
SingularityCmd.AddCommand(SearchCmd)
}
// SearchCmd singularity search
var SearchCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
PreRun: sylabsToken,
Run: func(cmd *cobra.Command, args []string) {
if err := client.SearchLibrary(args[0], SearchLibraryURI, authToken); err != nil {
sylog.Fatalf("Couldn't search library: %v", err)
}
},
Use: docs.SearchUse,
Short: docs.SearchShort,
Long: docs.SearchLong,
Example: docs.SearchExample,
}