MCPcopy Index your code
hub / github.com/VirusTotal/vt-cli / GetAndPrintObjectsWithFallback

Method GetAndPrintObjectsWithFallback

utils/printer.go:171–209  ·  view source on GitHub ↗

GetAndPrintObjectsWithFallback retrieves objects from the specified endpoints and prints them. The function tries the endpoints in the order they are provided until one of them returns the object. The endpoint must contain a %s placeholder that will be replaced with items from the args slice. If arg

(endpoints []string, r StringReader, argRe *regexp.Regexp)

Source from the content-addressed store, hash-verified

169// "-" string, the args are read from stdin one per line. If argRe is non-nil, only
170// args that match the regular expression are used and the rest are discarded.
171func (p *Printer) GetAndPrintObjectsWithFallback(endpoints []string, r StringReader, argRe *regexp.Regexp) error {
172 if argRe != nil {
173 r = NewFilteredStringReader(r, argRe)
174 }
175
176 filteredArgs := make([]string, 0)
177 for s, err := r.ReadString(); s != "" || err == nil; s, err = r.ReadString() {
178 filteredArgs = append(filteredArgs, s)
179 }
180
181 objectsCh := make(chan *vt.Object)
182 errorsCh := make(chan error, len(filteredArgs))
183
184 go p.client.RetrieveObjectsWithFallback(endpoints, filteredArgs, objectsCh, errorsCh)
185
186 if viper.GetBool("identifiers-only") {
187 var objectIds []string
188 for obj := range objectsCh {
189 objectIds = append(objectIds, obj.ID())
190 }
191 if err := p.Print(objectIds); err != nil {
192 return err
193 }
194 } else {
195 var objects []*vt.Object
196 for obj := range objectsCh {
197 objects = append(objects, obj)
198 }
199 if err := p.PrintObjects(objects); err != nil {
200 return err
201 }
202 }
203
204 for err := range errorsCh {
205 fmt.Fprintln(os.Stderr, err)
206 }
207
208 return nil
209}
210
211// PrintCollection prints a collection of objects retrieved from the collection
212// specified by the collection URL.

Callers 3

GetAndPrintObjectsMethod · 0.95
NewFileCmdFunction · 0.95
NewURLCmdFunction · 0.95

Calls 5

PrintMethod · 0.95
PrintObjectsMethod · 0.95
NewFilteredStringReaderFunction · 0.85
ReadStringMethod · 0.65

Tested by

no test coverage detected