Compare commits

..

No commits in common. "8f942f6f608dd9fc405613061d134a1cc72fb1e1" and "69d38d704844de95302fe1fc7cdeea9fed9e4162" have entirely different histories.

3 changed files with 40 additions and 49 deletions

View File

@ -80,9 +80,6 @@ func main() {
if emmyType == "@param" {
em.Params = append(em.Params, emmyLinePieces[1])
}
if emmyType == "@vararg" {
em.Params = append(em.Params, "...") // add vararg
}
em.Docs = append(em.Docs, d)
} else {
funcdoc = append(funcdoc, d)
@ -114,9 +111,6 @@ func main() {
if emmyType == "@param" {
em.Params = append(em.Params, emmyLinePieces[1])
}
if emmyType == "@vararg" {
em.Params = append(em.Params, "...") // add vararg
}
em.Docs = append(em.Docs, d)
} else {
funcdoc = append(funcdoc, d)

View File

@ -15,6 +15,6 @@ function bait.catchOnce(name, cb) end
--- Throws a hook with `name` with the provided `args`
--- @param name string
--- @vararg any
function bait.throw(name, ...) end
function bait.throw(name) end
return bait

81
exec.go
View File

@ -37,37 +37,37 @@ func runInput(input string, priv bool) {
case "hybrid":
_, err := handleLua(cmdString)
if err == nil {
cmdFinish(0, input, priv)
cmdFinish(0, cmdString, priv)
return
}
exitCode, err := handleSh(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
cmdFinish(exitCode, input, priv)
cmdFinish(exitCode, cmdString, priv)
case "hybridRev":
_, err := handleSh(cmdString)
if err == nil {
cmdFinish(0, input, priv)
cmdFinish(0, cmdString, priv)
return
}
exitCode, err := handleLua(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
cmdFinish(exitCode, input, priv)
cmdFinish(exitCode, cmdString, priv)
case "lua":
exitCode, err := handleLua(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
cmdFinish(exitCode, input, priv)
cmdFinish(exitCode, cmdString, priv)
case "sh":
exitCode, err := handleSh(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
cmdFinish(exitCode, input, priv)
cmdFinish(exitCode, cmdString, priv)
}
} else {
// can only be a string or function so
@ -75,7 +75,7 @@ func runInput(input string, priv bool) {
err := rt.Call(l.MainThread(), runnerMode, []rt.Value{rt.StringValue(cmdString)}, term)
if err != nil {
fmt.Fprintln(os.Stderr, err)
cmdFinish(124, input, priv)
cmdFinish(124, cmdString, priv)
return
}
@ -90,7 +90,7 @@ func runInput(input string, priv bool) {
if runErr != rt.NilValue {
fmt.Fprintln(os.Stderr, runErr)
}
cmdFinish(exitCode, input, priv)
cmdFinish(exitCode, cmdString, priv)
}
}
@ -159,45 +159,15 @@ func execCommand(cmd string, terminalOut bool) (io.Writer, io.Writer, error) {
if err != nil {
return nil, nil, err
}
runner, _ := interp.New()
var stdout io.Writer
var stderr io.Writer
if terminalOut {
interp.StdIO(os.Stdin, os.Stdout, os.Stderr)(runner)
} else {
var stdout io.Writer = os.Stdout
var stderr io.Writer = os.Stderr
if !terminalOut {
stdout = new(bytes.Buffer)
stderr = new(bytes.Buffer)
interp.StdIO(os.Stdin, stdout, stderr)(runner)
}
buf := new(bytes.Buffer)
printer := syntax.NewPrinter()
var bg bool
for _, stmt := range file.Stmts {
bg = false
if stmt.Background {
bg = true
printer.Print(buf, stmt.Cmd)
stmtStr := buf.String()
buf.Reset()
jobs.add(stmtStr)
}
interp.ExecHandler(execHandle(bg))(runner)
err = runner.Run(context.TODO(), stmt)
if err != nil {
return stdout, stderr, err
}
}
return stdout, stderr, nil
}
func execHandle(bg bool) interp.ExecHandlerFunc {
return func(ctx context.Context, args []string) error {
exechandle := func(ctx context.Context, args []string) error {
_, argstring := splitInput(strings.Join(args, " "))
// i dont really like this but it works
if aliases.All()[args[0]] != "" {
@ -358,6 +328,33 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
}
return interp.NewExitStatus(exit)
}
runner, _ := interp.New(
interp.StdIO(os.Stdin, stdout, stderr),
interp.ExecHandler(exechandle),
)
buf := new(bytes.Buffer)
printer := syntax.NewPrinter()
for _, stmt := range file.Stmts {
bg = false
if stmt.Background {
bg = true
printer.Print(buf, stmt.Cmd)
stmtStr := buf.String()
buf.Reset()
jobs.add(stmtStr)
}
err = runner.Run(context.TODO(), stmt)
if err != nil {
return stdout, stderr, err
}
}
return stdout, stderr, nil
}
func lookpath(file string) error { // custom lookpath function so we know if a command is found *and* is executable