-
Notifications
You must be signed in to change notification settings - Fork 1
/
directive.go
50 lines (42 loc) · 1.38 KB
/
directive.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
package systemdconf
import "strings"
// Directive holds a single systemd directive within a unit file.
type Directive struct {
Name string
Value string
}
// String returns a string representation of the directive.
func (d Directive) String() string {
return d.Name + "=" + d.Value
}
// Directives is a slice of systemd directives.
type Directives []Directive
// Add appends a directive to the list with the given name and value.
func (list *Directives) Add(name, value string) {
(*list) = append(*list, Directive{Name: name, Value: value})
}
// AddOptional appends a directive to the list with the given name and value.
//
// If no values is supplied, the directive will not be added.
func (list *Directives) AddOptional(name, value string) {
if value != "" {
(*list) = append(*list, Directive{Name: name, Value: value})
}
}
// AddDelimited appends a single directive to the list with the given name
// and values.
//
// If more than one value is supplied, the values will be space delimited.
//
// If no values are supplied, the directive will not be added.
func (list *Directives) AddDelimited(name string, values []string) {
if len(values) > 0 {
list.Add(name, strings.Join(values, " "))
}
}
// AddMany appends a separate directive for each value in the values list.
func (list *Directives) AddMany(name string, values []string) {
for _, value := range values {
list.Add(name, value)
}
}