Compare commits

...

4 Commits

Author SHA1 Message Date
TorchedSammy 8f942f6f60 docs: [ci] generate new docs 2022-04-05 01:35:10 +00:00
TorchedSammy b712efd278
fix(docgen): make functions that take varargs have the signature 2022-04-04 21:34:46 -04:00
TorchedSammy ee4d97ff9a
fix: put input in history instead of resolved input ran by hilbish
ive fixed this like 3 times and regressed it
2022-04-04 21:21:46 -04:00
TorchedSammy 9ce861b080
refactor: set runner options in a better way and move out exec handler 2022-04-04 21:20:02 -04:00
3 changed files with 49 additions and 40 deletions

View File

@ -80,6 +80,9 @@ 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)
@ -111,6 +114,9 @@ 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, cmdString, priv)
cmdFinish(0, input, priv)
return
}
exitCode, err := handleSh(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
cmdFinish(exitCode, cmdString, priv)
cmdFinish(exitCode, input, priv)
case "hybridRev":
_, err := handleSh(cmdString)
if err == nil {
cmdFinish(0, cmdString, priv)
cmdFinish(0, input, priv)
return
}
exitCode, err := handleLua(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
cmdFinish(exitCode, cmdString, priv)
cmdFinish(exitCode, input, priv)
case "lua":
exitCode, err := handleLua(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
cmdFinish(exitCode, cmdString, priv)
cmdFinish(exitCode, input, priv)
case "sh":
exitCode, err := handleSh(cmdString)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
cmdFinish(exitCode, cmdString, priv)
cmdFinish(exitCode, input, 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, cmdString, priv)
cmdFinish(124, input, priv)
return
}
@ -90,7 +90,7 @@ func runInput(input string, priv bool) {
if runErr != rt.NilValue {
fmt.Fprintln(os.Stderr, runErr)
}
cmdFinish(exitCode, cmdString, priv)
cmdFinish(exitCode, input, priv)
}
}
@ -159,15 +159,45 @@ func execCommand(cmd string, terminalOut bool) (io.Writer, io.Writer, error) {
if err != nil {
return nil, nil, err
}
var stdout io.Writer = os.Stdout
var stderr io.Writer = os.Stderr
if !terminalOut {
runner, _ := interp.New()
var stdout io.Writer
var stderr io.Writer
if terminalOut {
interp.StdIO(os.Stdin, os.Stdout, os.Stderr)(runner)
} else {
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
exechandle := func(ctx context.Context, args []string) error {
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 {
_, argstring := splitInput(strings.Join(args, " "))
// i dont really like this but it works
if aliases.All()[args[0]] != "" {
@ -328,33 +358,6 @@ func execCommand(cmd string, terminalOut bool) (io.Writer, io.Writer, error) {
}
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