-
Notifications
You must be signed in to change notification settings - Fork 13
/
check.go
45 lines (40 loc) · 1.07 KB
/
check.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
package massh
import (
"errors"
"fmt"
)
var (
// ErrJobConflict indicates that both Job and Jobstack are assigned in Config.
ErrJobConflict = errors.New("only one of job or jobstack must be present in config")
// ErrNoJobsSet indicates that no job is set for the config.
ErrNoJobsSet = errors.New("no jobs are set in config")
)
// TODO: Make this more robust, and automatically performed when running config.Run or config.Stream.
func checkConfigSanity(c *Config) error {
var e []string
if c.Hosts == nil {
e = append(e, "Hosts")
}
if c.Job == nil && c.JobStack == nil {
e = append(e, "Jobs")
}
if c.SSHConfig == nil {
e = append(e, "SSHConfig")
}
// not setting a worker pool results program hanging forever.
if c.WorkerPool == 0 {
e = append(e, "WorkerPool")
}
if e != nil {
return fmt.Errorf("bad config, the following config items are not correct: %s", e[0:])
}
return nil
}
func checkJobs(c *Config) error {
if c.Job != nil && c.JobStack != nil {
return ErrJobConflict
} else if c.Job == nil && c.JobStack == nil {
return ErrNoJobsSet
}
return nil
}