Wire up file running.

This commit is contained in:
Mariano Uvalle 2023-05-06 22:53:19 +00:00
parent ad1a8cac34
commit d7c5a19f85
3 changed files with 15 additions and 5 deletions

View file

@ -2,10 +2,13 @@ package runner
import (
"bufio"
"errors"
"fmt"
"os"
)
var ErrInvalidScriptFile = errors.New("could not read script file")
func RunPrompt() {
s := bufio.NewScanner(os.Stdin)
fmt.Print("> ")
@ -20,7 +23,7 @@ func RunPrompt() {
func RunFile(path string) error {
fBytes, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("could not read script file: %w", err)
return errors.Join(ErrInvalidScriptFile, err)
}
Run(string(fBytes))
// TODO: check hadError and exit with a 65 code if so.