2019-01-06 06:44:33 +08:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
|
2020-06-01 07:12:36 +08:00
|
|
|
"github.com/filebrowser/filebrowser/v2/settings"
|
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) {
|
2020-06-01 07:12:36 +08:00
|
|
|
var command []string
|
2019-01-06 06:44:33 +08:00
|
|
|
|
2024-08-31 03:24:45 +08:00
|
|
|
if len(s.Shell) == 0 || s.Shell[0] == "" {
|
2022-07-19 06:58:50 +08:00
|
|
|
cmd, args, err := SplitCommandAndArgs(raw)
|
2019-01-06 06:44:33 +08:00
|
|
|
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 {
|
2020-06-01 07:12:36 +08:00
|
|
|
command = append(s.Shell, raw) //nolint:gocritic
|
2019-01-06 06:44:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return command, nil
|
|
|
|
}
|