2017-07-09 10:45:49 +00:00
|
|
|
package restic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TagList is a list of tags.
|
|
|
|
type TagList []string
|
|
|
|
|
2017-07-09 18:28:38 +00:00
|
|
|
// splitTagList splits a string into a list of tags. The tags in the string
|
2017-07-09 10:45:49 +00:00
|
|
|
// need to be separated by commas. Whitespace is stripped around the individual
|
|
|
|
// tags.
|
2017-07-09 18:28:38 +00:00
|
|
|
func splitTagList(s string) (l TagList) {
|
2017-07-09 10:45:49 +00:00
|
|
|
for _, t := range strings.Split(s, ",") {
|
|
|
|
l = append(l, strings.TrimSpace(t))
|
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l TagList) String() string {
|
|
|
|
return "[" + strings.Join(l, ", ") + "]"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set updates the TagList's value.
|
|
|
|
func (l *TagList) Set(s string) error {
|
2017-07-09 18:28:38 +00:00
|
|
|
*l = splitTagList(s)
|
2017-07-09 10:45:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type returns a description of the type.
|
|
|
|
func (TagList) Type() string {
|
|
|
|
return "TagList"
|
|
|
|
}
|
|
|
|
|
|
|
|
// TagLists consists of several TagList.
|
|
|
|
type TagLists []TagList
|
|
|
|
|
2017-07-09 18:28:38 +00:00
|
|
|
// splitTagLists splits a slice of strings into a slice of TagLists using
|
2017-07-09 10:45:49 +00:00
|
|
|
// SplitTagList.
|
2017-07-09 18:28:38 +00:00
|
|
|
func splitTagLists(s []string) (l TagLists) {
|
2017-07-09 10:45:49 +00:00
|
|
|
l = make([]TagList, 0, len(s))
|
|
|
|
for _, t := range s {
|
2017-07-09 18:28:38 +00:00
|
|
|
l = append(l, splitTagList(t))
|
2017-07-09 10:45:49 +00:00
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l TagLists) String() string {
|
|
|
|
return fmt.Sprintf("%v", []TagList(l))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set updates the TagList's value.
|
|
|
|
func (l *TagLists) Set(s string) error {
|
2017-07-09 18:28:38 +00:00
|
|
|
*l = append(*l, splitTagList(s))
|
2017-07-09 10:45:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type returns a description of the type.
|
|
|
|
func (TagLists) Type() string {
|
|
|
|
return "TagLists"
|
|
|
|
}
|