2019-01-06 06:44:33 +08:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
"github.com/filebrowser/filebrowser/v2/settings"
|
2019-01-06 07:01:16 +08:00
|
|
|
"github.com/mholt/caddy"
|
2019-01-06 06:44:33 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// ParseCommand parses the command taking in account if the current
|
|
|
|
// instance uses a shell to run the commands or just calls the binary
|
|
|
|
// directyly.
|
|
|
|
func ParseCommand(s *settings.Settings, raw string) ([]string, error) {
|
|
|
|
command := []string{}
|
|
|
|
|
|
|
|
if len(s.Shell) == 0 {
|
|
|
|
cmd, args, err := caddy.SplitCommandAndArgs(raw)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = exec.LookPath(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
command = append(command, cmd)
|
|
|
|
command = append(command, args...)
|
|
|
|
} else {
|
|
|
|
command = append(s.Shell, raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
return command, nil
|
|
|
|
}
|