2019-03-13 04:14:30 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
type command struct {
|
|
|
|
props *properties
|
|
|
|
env environmentInfo
|
|
|
|
value string
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2020-11-12 00:43:32 -08:00
|
|
|
// ExecutableShell to execute command in
|
2020-09-23 00:33:54 -07:00
|
|
|
ExecutableShell Property = "shell"
|
2020-11-12 00:43:32 -08:00
|
|
|
// Command to execute
|
2019-03-13 04:14:30 -07:00
|
|
|
Command Property = "command"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *command) enabled() bool {
|
2020-09-23 00:33:54 -07:00
|
|
|
shell := c.props.getString(ExecutableShell, "bash")
|
2020-10-04 02:32:26 -07:00
|
|
|
if !c.env.hasCommand(shell) {
|
|
|
|
return false
|
|
|
|
}
|
2019-03-13 04:14:30 -07:00
|
|
|
command := c.props.getString(Command, "echo no command specified")
|
|
|
|
if strings.Contains(command, "||") {
|
|
|
|
commands := strings.Split(command, "||")
|
|
|
|
for _, cmd := range commands {
|
|
|
|
output := c.env.runShellCommand(shell, cmd)
|
|
|
|
if output != "" {
|
|
|
|
c.value = output
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if strings.Contains(command, "&&") {
|
|
|
|
var output string
|
|
|
|
commands := strings.Split(command, "&&")
|
|
|
|
for _, cmd := range commands {
|
|
|
|
output += c.env.runShellCommand(shell, cmd)
|
|
|
|
}
|
|
|
|
c.value = output
|
|
|
|
return c.value != ""
|
|
|
|
}
|
|
|
|
c.value = c.env.runShellCommand(shell, command)
|
|
|
|
return c.value != ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *command) string() string {
|
|
|
|
return c.value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *command) init(props *properties, env environmentInfo) {
|
|
|
|
c.props = props
|
|
|
|
c.env = env
|
|
|
|
}
|