fix zoa-script
Jes Olson j3s@c3f.net
Sun, 09 Oct 2022 01:11:41 -0500
2 files changed,
20 insertions(+),
9 deletions(-)
M
main.go
→
main.go
@@ -5,6 +5,7 @@ "fmt"
"log" "os" "os/exec" + "path/filepath" "j3s.sh/zoa/env" "j3s.sh/zoa/shell"@@ -54,9 +55,10 @@ log.Fatal(err)
} session := &shell.Session{ - ScriptPath: path, - Runner: r, - SubShell: false, + ScriptPath: path, + ScriptBaseDir: filepath.Dir(path), + Runner: r, + SubShell: false, } // todo: err?
M
shell/shell.go
→
shell/shell.go
@@ -31,15 +31,18 @@ // the primary script the user called
// var zoaRoot string type Session struct { - Runner *interp.Runner - ScriptPath string - SubShell bool + Runner *interp.Runner + ScriptPath string + ScriptBaseDir string + SubShell bool } func (s *Session) Run() { - color.BluePrintln("./" + filepath.Base(s.ScriptPath)) ctx := context.TODO() + // TODO: just pass the whole session u idiot ctx = context.WithValue(ctx, "script", s.ScriptPath) + ctx = context.WithValue(ctx, "scriptbasedir", s.ScriptBaseDir) + ctx = context.WithValue(ctx, "runner", s.Runner) f, err := parseFile(s.ScriptPath) if err != nil { log.Fatal(err)@@ -62,8 +65,7 @@ }
} func CallHandler(ctx context.Context, args []string) ([]string, error) { - var script string - script = ctx.Value("script").(string) + script := ctx.Value("script").(string) command := args[0] fmt.Println()@@ -80,6 +82,13 @@ if len(args) <= 1 {
// log.Fatal here? return args, fmt.Errorf("zoa-script requires 1 argument: the script to run") } + s := &Session{ + Runner: ctx.Value("runner").(*interp.Runner), + SubShell: true, + ScriptPath: filepath.Join(ctx.Value("scriptbasedir").(string), "scripts", args[1]), + ScriptBaseDir: ctx.Value("scriptbasedir").(string), + } + s.Run() // session.Run() // subScript := filepath.Join("scripts", args[1]) // err := RunScript(subScript)