put code in right palce

This commit is contained in:
Shane C 2024-07-09 19:13:10 -04:00
parent 991429a290
commit 182f75e37a
Signed by: shane
GPG key ID: E46B5FEA35B22FF9

View file

@ -51,6 +51,15 @@ func (cmd *LinuxCommand) AddHandler(handler interface{}) error {
func (cmd *LinuxCommand) Run() error { func (cmd *LinuxCommand) Run() error {
isCommandExecutable, err := cmd.isCommandExecutable(cmd.Options.Command)
if err != nil {
return err
}
if !isCommandExecutable {
return ErrCommandNotExecutable
}
var sourceCommand strings.Builder var sourceCommand strings.Builder
for _, value := range cmd.Options.Sources { for _, value := range cmd.Options.Sources {
sourceCommand.WriteString(fmt.Sprintf("source %s && ", value)) sourceCommand.WriteString(fmt.Sprintf("source %s && ", value))
@ -100,7 +109,6 @@ func (cmd *LinuxCommand) Run() error {
if err := command.Start(); err != nil { if err := command.Start(); err != nil {
var exitErr *exec.ExitError var exitErr *exec.ExitError
if errors.As(err, &exitErr) { if errors.As(err, &exitErr) {
fmt.Println(exitErr.String())
if exitErr.ExitCode() == 127 { if exitErr.ExitCode() == 127 {
return ErrCommandNotFound return ErrCommandNotFound
} else if _, ok := cmd.Options.CustomErrors[int8(exitErr.ExitCode())]; ok { } else if _, ok := cmd.Options.CustomErrors[int8(exitErr.ExitCode())]; ok {
@ -160,15 +168,6 @@ func (cmd *LinuxCommand) Run() error {
} }
}() }()
isCommandExecutable, err := cmd.isCommandExecutable(cmd.Options.Command)
if err != nil {
return err
}
if !isCommandExecutable {
return ErrCommandNotExecutable
}
var exitInfo *EventExitData var exitInfo *EventExitData
if _, ok := cmd.handlers[EventExit]; ok { if _, ok := cmd.handlers[EventExit]; ok {