mirror of https://github.com/Hilbis/Hilbish
refactor: reorder returns of handleSh function
parent
02fb7c3238
commit
ade570d598
18
exec.go
18
exec.go
|
@ -101,9 +101,9 @@ func runInput(input string, priv bool) {
|
||||||
cmdFinish(0, input, priv)
|
cmdFinish(0, input, priv)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
input, exitCode, err, cont = handleSh(input)
|
input, exitCode, cont, err = handleSh(input)
|
||||||
case "hybridRev":
|
case "hybridRev":
|
||||||
_, _, err, cont = handleSh(input)
|
_, _, _, err = handleSh(input)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cmdFinish(0, input, priv)
|
cmdFinish(0, input, priv)
|
||||||
return
|
return
|
||||||
|
@ -112,7 +112,7 @@ func runInput(input string, priv bool) {
|
||||||
case "lua":
|
case "lua":
|
||||||
input, exitCode, err = handleLua(cmdString)
|
input, exitCode, err = handleLua(cmdString)
|
||||||
case "sh":
|
case "sh":
|
||||||
input, exitCode, err, cont = handleSh(input)
|
input, exitCode, cont, err = handleSh(input)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// can only be a string or function so
|
// can only be a string or function so
|
||||||
|
@ -197,25 +197,25 @@ func handleLua(cmdString string) (string, uint8, error) {
|
||||||
return cmdString, 125, err
|
return cmdString, 125, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSh(cmdString string) (string, uint8, error, bool) {
|
func handleSh(cmdString string) (string, uint8, bool, error) {
|
||||||
_, _, err := execCommand(cmdString, true)
|
_, _, err := execCommand(cmdString, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If input is incomplete, start multiline prompting
|
// If input is incomplete, start multiline prompting
|
||||||
if syntax.IsIncomplete(err) {
|
if syntax.IsIncomplete(err) {
|
||||||
if !interactive {
|
if !interactive {
|
||||||
return cmdString, 126, err, false
|
return cmdString, 126, false, err
|
||||||
}
|
}
|
||||||
return cmdString, 126, err, true
|
return cmdString, 126, true, err
|
||||||
} else {
|
} else {
|
||||||
if code, ok := interp.IsExitStatus(err); ok {
|
if code, ok := interp.IsExitStatus(err); ok {
|
||||||
return cmdString, code, nil, false
|
return cmdString, code, false, nil
|
||||||
} else {
|
} else {
|
||||||
return cmdString, 126, err, false
|
return cmdString, 126, false, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmdString, 0, nil, false
|
return cmdString, 0, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run command in sh interpreter
|
// Run command in sh interpreter
|
||||||
|
|
|
@ -28,7 +28,7 @@ func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
input, exitCode, err, cont := handleSh(cmd)
|
input, exitCode, cont, err := handleSh(cmd)
|
||||||
var luaErr rt.Value = rt.NilValue
|
var luaErr rt.Value = rt.NilValue
|
||||||
if err != nil {
|
if err != nil {
|
||||||
luaErr = rt.StringValue(err.Error())
|
luaErr = rt.StringValue(err.Error())
|
||||||
|
|
Loading…
Reference in New Issue