-
Notifications
You must be signed in to change notification settings - Fork 58
/
search.go
67 lines (61 loc) · 1.63 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
61
62
63
64
65
66
67
package generic
import (
"github.com/jfrog/jfrog-cli-core/artifactory/utils"
clientartutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/content"
"github.com/jfrog/jfrog-client-go/utils/log"
)
type SearchCommand struct {
GenericCommand
}
func NewSearchCommand() *SearchCommand {
return &SearchCommand{GenericCommand: *NewGenericCommand()}
}
func (sc *SearchCommand) CommandName() string {
return "rt_search"
}
func (sc *SearchCommand) Run() error {
reader, err := sc.Search()
sc.Result().SetReader(reader)
return err
}
func (sc *SearchCommand) Search() (*content.ContentReader, error) {
// Service Manager
serverDetails, err := sc.ServerDetails()
if errorutils.CheckError(err) != nil {
return nil, err
}
servicesManager, err := utils.CreateServiceManager(serverDetails, sc.retries, false)
if err != nil {
return nil, err
}
// Search Loop
log.Info("Searching artifacts...")
var searchResults []*content.ContentReader
defer func() {
for _, reader := range searchResults {
reader.Close()
}
}()
for i := 0; i < len(sc.Spec().Files); i++ {
searchParams, err := utils.GetSearchParams(sc.Spec().Get(i))
if err != nil {
log.Error(err)
return nil, err
}
reader, err := servicesManager.SearchFiles(searchParams)
if err != nil {
log.Error(err)
return nil, err
}
searchResults = append(searchResults, reader)
}
reader, err := utils.AqlResultToSearchResult(searchResults)
if err != nil {
return nil, err
}
length, err := reader.Length()
clientartutils.LogSearchResults(length)
return reader, err
}