github.com/mckael/restic@v0.8.3/internal/restic/tag_list.go (about)

     1  package restic
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  // TagList is a list of tags.
     9  type TagList []string
    10  
    11  // splitTagList splits a string into a list of tags. The tags in the string
    12  // need to be separated by commas. Whitespace is stripped around the individual
    13  // tags.
    14  func splitTagList(s string) (l TagList) {
    15  	for _, t := range strings.Split(s, ",") {
    16  		l = append(l, strings.TrimSpace(t))
    17  	}
    18  	return l
    19  }
    20  
    21  func (l TagList) String() string {
    22  	return "[" + strings.Join(l, ", ") + "]"
    23  }
    24  
    25  // Set updates the TagList's value.
    26  func (l *TagList) Set(s string) error {
    27  	*l = splitTagList(s)
    28  	return nil
    29  }
    30  
    31  // Type returns a description of the type.
    32  func (TagList) Type() string {
    33  	return "TagList"
    34  }
    35  
    36  // TagLists consists of several TagList.
    37  type TagLists []TagList
    38  
    39  // splitTagLists splits a slice of strings into a slice of TagLists using
    40  // SplitTagList.
    41  func splitTagLists(s []string) (l TagLists) {
    42  	l = make([]TagList, 0, len(s))
    43  	for _, t := range s {
    44  		l = append(l, splitTagList(t))
    45  	}
    46  	return l
    47  }
    48  
    49  func (l TagLists) String() string {
    50  	return fmt.Sprintf("%v", []TagList(l))
    51  }
    52  
    53  // Set updates the TagList's value.
    54  func (l *TagLists) Set(s string) error {
    55  	*l = append(*l, splitTagList(s))
    56  	return nil
    57  }
    58  
    59  // Type returns a description of the type.
    60  func (TagLists) Type() string {
    61  	return "TagLists"
    62  }