mirror of https://github.com/Hilbis/Hilbish
Compare commits
4 Commits
69d38d7048
...
8f942f6f60
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 8f942f6f60 | |
TorchedSammy | b712efd278 | |
TorchedSammy | ee4d97ff9a | |
TorchedSammy | 9ce861b080 |
|
@ -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)
|
||||
|
|
|
@ -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
81
exec.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue