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" { if emmyType == "@param" {
em.Params = append(em.Params, emmyLinePieces[1]) em.Params = append(em.Params, emmyLinePieces[1])
} }
if emmyType == "@vararg" {
em.Params = append(em.Params, "...") // add vararg
}
em.Docs = append(em.Docs, d) em.Docs = append(em.Docs, d)
} else { } else {
funcdoc = append(funcdoc, d) funcdoc = append(funcdoc, d)
@ -114,9 +111,6 @@ func main() {
if emmyType == "@param" { if emmyType == "@param" {
em.Params = append(em.Params, emmyLinePieces[1]) em.Params = append(em.Params, emmyLinePieces[1])
} }
if emmyType == "@vararg" {
em.Params = append(em.Params, "...") // add vararg
}
em.Docs = append(em.Docs, d) em.Docs = append(em.Docs, d)
} else { } else {
funcdoc = append(funcdoc, d) 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` --- Throws a hook with `name` with the provided `args`
--- @param name string --- @param name string
--- @vararg any --- @vararg any
function bait.throw(name, ...) end function bait.throw(name) end
return bait return bait

81
exec.go
View File

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