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" {
|
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)
|
||||||
|
@ -111,6 +114,9 @@ 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)
|
||||||
|
|
|
@ -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
81
exec.go
|
@ -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, cmdString, priv)
|
cmdFinish(0, input, 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, cmdString, priv)
|
cmdFinish(exitCode, input, priv)
|
||||||
case "hybridRev":
|
case "hybridRev":
|
||||||
_, err := handleSh(cmdString)
|
_, err := handleSh(cmdString)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cmdFinish(0, cmdString, priv)
|
cmdFinish(0, input, 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, cmdString, priv)
|
cmdFinish(exitCode, input, 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, cmdString, priv)
|
cmdFinish(exitCode, input, 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, cmdString, priv)
|
cmdFinish(exitCode, input, 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, cmdString, priv)
|
cmdFinish(124, input, 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, cmdString, priv)
|
cmdFinish(exitCode, input, priv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,15 +159,45 @@ 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
|
|
||||||
var stderr io.Writer = os.Stderr
|
runner, _ := interp.New()
|
||||||
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
|
||||||
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, " "))
|
_, 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]] != "" {
|
||||||
|
@ -328,33 +358,6 @@ func execCommand(cmd string, terminalOut bool) (io.Writer, io.Writer, error) {
|
||||||
}
|
}
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue