Switch to a single key for command and command shell
This makes the configuration more similar to Minitor-py and docker-compose. If a string is passed, it will be executed in a shell. If an array is passed, it will be executed in as a command directly. This breaks compatiblity with previous versions of Minitor-go, but closer to compatiblity with Minitor-py.
This commit is contained in:
@@ -15,6 +15,37 @@ type Config struct {
|
||||
Alerts map[string]*Alert
|
||||
}
|
||||
|
||||
// CommandOrShell type wraps a string or list of strings
|
||||
// for executing a command directly or in a shell
|
||||
type CommandOrShell struct {
|
||||
ShellCommand string
|
||||
Command []string
|
||||
}
|
||||
|
||||
// Empty checks if the Command has a value
|
||||
func (cos CommandOrShell) Empty() bool {
|
||||
return (cos.ShellCommand == "" && cos.Command == nil)
|
||||
}
|
||||
|
||||
// UnmarshalYAML allows unmarshalling either a string or slice of strings
|
||||
// and parsing them as either a command or a shell command.
|
||||
func (cos *CommandOrShell) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var cmd []string
|
||||
err := unmarshal(&cmd)
|
||||
// Error indicates this is shell command
|
||||
if err != nil {
|
||||
var shellCmd string
|
||||
err := unmarshal(&shellCmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cos.ShellCommand = shellCmd
|
||||
} else {
|
||||
cos.Command = cmd
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsValid checks config validity and returns true if valid
|
||||
func (config Config) IsValid() (isValid bool) {
|
||||
isValid = true
|
||||
|
||||
Reference in New Issue
Block a user