podman
40 строк · 1020.0 Байт
1package specgenutilexternal2
3import (4"encoding/csv"5"errors"6"strings"7)
8
9var (10errInvalidSyntax = errors.New("incorrect mount format: should be --mount type=<bind|glob|tmpfs|volume>,[src=<host-dir|volume-name>,]target=<ctr-dir>[,options]")11)
12
13// FindMountType parses the input and extracts the type of the mount type and
14// the remaining non-type tokens.
15func FindMountType(input string) (mountType string, tokens []string, err error) {16// Split by comma, iterate over the slice and look for17// "type=$mountType". Everything else is appended to tokens.18found := false19csvReader := csv.NewReader(strings.NewReader(input))20records, err := csvReader.ReadAll()21if err != nil {22return "", nil, err23}24if len(records) != 1 {25return "", nil, errInvalidSyntax26}27for _, s := range records[0] {28kv := strings.Split(s, "=")29if found || !(len(kv) == 2 && kv[0] == "type") {30tokens = append(tokens, s)31continue32}33mountType = kv[1]34found = true35}36if !found {37err = errInvalidSyntax38}39return40}
41