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