podman

Форк
0
40 строк · 1020.0 Байт
1
package specgenutilexternal
2

3
import (
4
	"encoding/csv"
5
	"errors"
6
	"strings"
7
)
8

9
var (
10
	errInvalidSyntax = 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.
15
func FindMountType(input string) (mountType string, tokens []string, err error) {
16
	// Split by comma, iterate over the slice and look for
17
	// "type=$mountType". Everything else is appended to tokens.
18
	found := false
19
	csvReader := csv.NewReader(strings.NewReader(input))
20
	records, err := csvReader.ReadAll()
21
	if err != nil {
22
		return "", nil, err
23
	}
24
	if len(records) != 1 {
25
		return "", nil, errInvalidSyntax
26
	}
27
	for _, s := range records[0] {
28
		kv := strings.Split(s, "=")
29
		if found || !(len(kv) == 2 && kv[0] == "type") {
30
			tokens = append(tokens, s)
31
			continue
32
		}
33
		mountType = kv[1]
34
		found = true
35
	}
36
	if !found {
37
		err = errInvalidSyntax
38
	}
39
	return
40
}
41

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.