mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "0c3028bb03cd53a62f8b4f1f0edd374e7cb150b4" and "02fb7c3238670eb05926b7ecb1314dbe89ffdd12" have entirely different histories.
0c3028bb03
...
02fb7c3238
88
exec.go
88
exec.go
|
@ -101,9 +101,9 @@ func runInput(input string, priv bool) {
|
||||||
cmdFinish(0, input, priv)
|
cmdFinish(0, input, priv)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
input, exitCode, cont, err = handleSh(input)
|
input, exitCode, err, cont = handleSh(input)
|
||||||
case "hybridRev":
|
case "hybridRev":
|
||||||
_, _, _, err = handleSh(input)
|
_, _, err, cont = handleSh(input)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cmdFinish(0, input, priv)
|
cmdFinish(0, input, priv)
|
||||||
return
|
return
|
||||||
|
@ -112,57 +112,17 @@ 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, cont, err = handleSh(input)
|
input, exitCode, err, cont = handleSh(input)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// can only be a string or function so
|
// can only be a string or function so
|
||||||
input, exitCode, cont, err = runLuaRunner(currentRunner, input)
|
term := rt.NewTerminationWith(l.MainThread().CurrentCont(), 3, false)
|
||||||
|
err = rt.Call(l.MainThread(), currentRunner, []rt.Value{rt.StringValue(input)}, term)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
cmdFinish(124, input, priv)
|
cmdFinish(124, input, priv)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if cont {
|
|
||||||
input, err = reprompt(input)
|
|
||||||
if err == nil {
|
|
||||||
goto rerun
|
|
||||||
} else if err == io.EOF {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
if exErr, ok := isExecError(err); ok {
|
|
||||||
hooks.Em.Emit("command." + exErr.typ, exErr.cmd)
|
|
||||||
err = exErr.sprint()
|
|
||||||
}
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
}
|
|
||||||
cmdFinish(exitCode, input, priv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func reprompt(input string) (string, error) {
|
|
||||||
for {
|
|
||||||
in, err := continuePrompt(strings.TrimSuffix(input, "\\"))
|
|
||||||
if err != nil {
|
|
||||||
return input, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasSuffix(in, "\\") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return in, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8, continued bool, err error) {
|
|
||||||
term := rt.NewTerminationWith(l.MainThread().CurrentCont(), 3, false)
|
|
||||||
err = rt.Call(l.MainThread(), runr, []rt.Value{rt.StringValue(userInput)}, term)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var runner *rt.Table
|
var runner *rt.Table
|
||||||
var ok bool
|
var ok bool
|
||||||
|
@ -184,9 +144,31 @@ func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
if c, ok := runner.Get(rt.StringValue("continue")).TryBool(); ok {
|
if c, ok := runner.Get(rt.StringValue("continue")).TryBool(); ok {
|
||||||
continued = c
|
cont = c
|
||||||
}
|
}
|
||||||
return
|
}
|
||||||
|
|
||||||
|
if cont {
|
||||||
|
for {
|
||||||
|
input, err = continuePrompt(strings.TrimSuffix(input, "\\"))
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(cmdString, "\\") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
goto rerun
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
if exErr, ok := isExecError(err); ok {
|
||||||
|
hooks.Em.Emit("command." + exErr.typ, exErr.cmd)
|
||||||
|
err = exErr.sprint()
|
||||||
|
}
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
}
|
||||||
|
cmdFinish(exitCode, input, priv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleLua(cmdString string) (string, uint8, error) {
|
func handleLua(cmdString string) (string, uint8, error) {
|
||||||
|
@ -215,25 +197,25 @@ func handleLua(cmdString string) (string, uint8, error) {
|
||||||
return cmdString, 125, err
|
return cmdString, 125, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSh(cmdString string) (string, uint8, bool, error) {
|
func handleSh(cmdString string) (string, uint8, error, bool) {
|
||||||
_, _, 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, false, err
|
return cmdString, 126, err, false
|
||||||
}
|
}
|
||||||
return cmdString, 126, true, err
|
return cmdString, 126, err, true
|
||||||
} else {
|
} else {
|
||||||
if code, ok := interp.IsExitStatus(err); ok {
|
if code, ok := interp.IsExitStatus(err); ok {
|
||||||
return cmdString, code, false, nil
|
return cmdString, code, nil, false
|
||||||
} else {
|
} else {
|
||||||
return cmdString, 126, false, err
|
return cmdString, 126, err, false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmdString, 0, false, nil
|
return cmdString, 0, nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, cont, err := handleSh(cmd)
|
input, exitCode, err, cont := 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