-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline.go
48 lines (41 loc) · 1022 Bytes
/
line.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
package cronfab
// CrontabLine represents the parsed user supplied contab specification
type CrontabLine [][][3]int
func (cl CrontabLine) String() string {
q := ""
for i := 0; i < len(cl); i++ {
if i > 0 {
q += " "
}
q += cl.GetField(i).String()
}
return q
}
// GetField return the crontab field at index i
func (cl CrontabLine) GetField(i int) CrontabField {
return cl[i]
}
// SetField set the crontab field at index i
func (cl *CrontabLine) SetField(i int, f CrontabField) {
(*cl)[i] = f
}
// SetConstraint set the field constraint for crontab field i, constraint j
func (cl *CrontabLine) SetConstraint(i int, j int, c CrontabConstraint) {
(*cl)[i][j] = c
}
// Sort the crontab sub-elements chronologically
func (cl CrontabLine) Sort() {
for i := range cl {
cl.GetField(i).Sort()
}
}
// Validate return an error if the crontab line is invalid
func (cl CrontabLine) Validate() error {
for i := range cl {
err := cl.GetField(i).Validate()
if err != nil {
return err
}
}
return nil
}