func listValuesForTag(store *storage.Storage, tagName string, showCount, onePerLine bool) error { tag, err := store.TagByName(tagName) if err != nil { return fmt.Errorf("could not retrieve tag '%v': %v", tagName, err) } if tag == nil { return fmt.Errorf("no such tag, '%v'.", tagName) } log.Infof(2, "retrieving values for tag '%v'.", tagName) values, err := store.ValuesByTag(tag.Id) if err != nil { return fmt.Errorf("could not retrieve values for tag '%v': %v", tagName, err) } if showCount { fmt.Println(len(values)) } else { if onePerLine { for _, value := range values { fmt.Println(value.Name) } } else { valueNames := make([]string, len(values)) for index, value := range values { valueNames[index] = value.Name } format.Columns(valueNames, terminalWidth()) } } return nil }
func listValuesForTags(store *storage.Storage, tagNames []string, showCount, onePerLine bool) error { wereErrors := false for _, tagName := range tagNames { tag, err := store.TagByName(tagName) if err != nil { return fmt.Errorf("could not retrieve tag '%v': %v", tagName, err) } if tag == nil { log.Warnf("no such tag, '%v'.", tagName) wereErrors = true continue } log.Infof(2, "retrieving values for tag '%v'.", tagName) values, err := store.ValuesByTag(tag.Id) if err != nil { return fmt.Errorf("could not retrieve values for tag '%v': %v", tagName, err) } if showCount { fmt.Printf("%v: %v\n", tagName, len(values)) } else { if onePerLine { fmt.Println(tagName) for _, value := range values { fmt.Println(value.Name) } fmt.Println() } else { valueNames := make([]string, len(values)) for index, value := range values { valueNames[index] = value.Name } fmt.Printf("%v: %v\n", tagName, strings.Join(valueNames, " ")) } } } if wereErrors { return blankError } return nil }