filebrowser/runner/parser.go
Henrique Dias ea434ffc04 🧹: gofmt
Former-commit-id: 9548d370497e13d436abbc670cf40d360badab9f [formerly f29ba9c4dcf9962c3a5045629526296cd2b43ad8] [formerly 3f89c094c1b3330c8d6f1b2379d6309567d12210 [formerly 92fda0070c]]
Former-commit-id: 4ad64211019e0236f0eaa6e041a8793e899954fe [formerly 6bf71ffba205b563ff6cd0c7487d9a328c757686]
Former-commit-id: 4c7afe072fc3e2a225ca5a7dbf3f3beb66b44058
2019-01-05 23:01:16 +00:00

35 lines
693 B
Go

package runner
import (
"os/exec"
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/mholt/caddy"
)
// 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
}