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)
| 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. |
| 171 | func (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. |
no test coverage detected