forked from GoogleCloudPlatform/gcsfuse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flag.go
58 lines (52 loc) · 1.76 KB
/
flag.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Helper functions for dealing with mount(8)-style flags.
package mount
import "strings"
// Parse an option string in the format accepted by mount(8) and generated for
// its external mount helpers.
//
// It is assumed that option name and values do not contain commas, and that
// the first equals sign in an option is the name/value separator. There is no
// support for escaping.
//
// For example, if the input is
//
// user,foo=bar=baz,qux
//
// then the following will be inserted into the map.
//
// "user": "",
// "foo": "bar=baz",
// "qux": "",
//
func ParseOptions(m map[string]string, s string) {
// NOTE(jacobsa): The man pages don't define how escaping works, and as far
// as I can tell there is no way to properly escape or quote a comma in the
// options list for an fstab entry. So put our fingers in our ears and hope
// that nobody needs a comma.
for _, p := range strings.Split(s, ",") {
var name string
var value string
// Split on the first equals sign.
if equalsIndex := strings.IndexByte(p, '='); equalsIndex != -1 {
name = p[:equalsIndex]
value = p[equalsIndex+1:]
} else {
name = p
}
m[name] = value
}
return
}