Welcome to mirror list, hosted at ThFree Co, Russian Federation.

multi_string_flag.go - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 699529a0d7d89e4e3d3aafe5b73cab94302c2227 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main

import (
	"errors"
	"strings"
)

var errMultiStringSetEmptyValue = errors.New("value cannot be empty")

// MultiStringFlag implements the flag.Value interface and allows a string flag
// to be specified multiple times on the command line.
//
// e.g.: -listen-http 127.0.0.1:80 -listen-http [::1]:80
type MultiStringFlag []string

// String returns the list of parameters joined with a commas (",")
func (s *MultiStringFlag) String() string {
	return strings.Join(*s, ",")
}

// Set appends the value to the list of parameters
func (s *MultiStringFlag) Set(value string) error {
	if value == "" {
		return errMultiStringSetEmptyValue
	}
	*s = append(*s, value)
	return nil
}

// Split each flag
func (s *MultiStringFlag) Split() (result []string) {
	for _, str := range *s {
		result = append(result, strings.Split(str, ",")...)
	}

	return
}