From e6382d454d26771e6f9dd637b73b4ea82d960d15 Mon Sep 17 00:00:00 2001 From: sammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 8 May 2021 08:56:24 -0400 Subject: [PATCH] feat: add -n flag (closes #47) --- main.go | 7 +++++++ shell.go | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 87ee7e9..b354585 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,7 @@ var ( hooks bait.Bait interactive bool login bool // Are we the login shell? + noexecute bool // Should we run Lua or only report syntax errors ) func main() { @@ -51,10 +52,12 @@ func main() { // TODO: issue #37 _ = getopt.BoolLong("login", 'l', "Makes Hilbish act like a login shell") _ = getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell") + _ = getopt.BoolLong("noexec", 'n', "Force Hilbish to be an interactive shell") getopt.Parse() loginshflag := getopt.Lookup('l').Seen() interactiveflag := getopt.Lookup('i').Seen() + noexecflag := getopt.Lookup('n').Seen() if *cmdflag == "" || interactiveflag { interactive = true @@ -64,6 +67,10 @@ func main() { interactive = false } + if noexecflag { + noexecute = true + } + // first arg, first character if loginshflag || os.Args[0][0] == '-' { login = true diff --git a/shell.go b/shell.go index 5507419..d9b6c05 100644 --- a/shell.go +++ b/shell.go @@ -16,9 +16,17 @@ import ( ) func RunInput(input string) { - // First try to run user input in Lua - err := l.DoString(input) - + // First try to load input, essentially compiling to bytecode + fn, err := l.LoadString(input) + if err != nil && noexecute { + fmt.Println(err) + return + } + // And if there's no syntax errors and -n isnt provided, run + if !noexecute { + l.Push(fn) + err = l.PCall(0, lua.MultRet, nil) + } if err == nil { // If it succeeds, add to history and prompt again HandleHistory(input)