feat: switch to getopt library and add running lua source files from cli

pull/45/head
sammy 2021-05-01 01:08:55 -04:00
parent e7dcbd5a95
commit 89fc544545
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
1 changed files with 19 additions and 36 deletions

55
main.go
View File

@ -10,13 +10,13 @@ import (
"hilbish/golibs/bait" "hilbish/golibs/bait"
"github.com/akamensky/argparse" "github.com/pborman/getopt"
"github.com/bobappleyard/readline" "github.com/bobappleyard/readline"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"golang.org/x/term" "golang.org/x/term"
) )
const version = "0.4.0-dev.3" const version = "0.4.0-dev.4"
var ( var (
l *lua.LState l *lua.LState
@ -38,44 +38,20 @@ func main() {
homedir, _ = os.UserHomeDir() homedir, _ = os.UserHomeDir()
defaultconfpath := homedir + "/.hilbishrc.lua" defaultconfpath := homedir + "/.hilbishrc.lua"
parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers") // parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers")
verflag := parser.Flag("v", "version", &argparse.Options{ verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
Required: false, setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path")
Help: "Prints Hilbish version", cmdflag := getopt.StringLong("command", 'c', "", /*TODO: Help description*/ "")
}) configflag := getopt.StringLong("config", 'C', defaultconfpath, "Sets the path to Hilbish's config")
setshflag := parser.Flag("S", "set-shell-env", &argparse.Options{
Required: false,
Help: "Sets $SHELL to Hilbish's executed path",
})
cmdflag := parser.String("c", "command", &argparse.Options{
Required: false,
// TODO: Help: "",
})
configflag := parser.String("C", "config", &argparse.Options{
Required: false,
Help: "Sets the path to Hilbish's config",
Default: defaultconfpath,
})
// loginshflag // loginshflag
// TODO: issue #37 // TODO: issue #37
_ = parser.Flag("l", "login", &argparse.Options{ _ = getopt.BoolLong("login", 'l', "Makes Hilbish act like a login shell")
Required: false, interactiveflag := getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
Help: "Makes Hilbish act like a login shell",
})
interactiveflag := parser.Flag("i", "interactive", &argparse.Options{
Required: false,
Help: "Force Hilbish to be an interactive shell",
})
err := parser.Parse(os.Args) getopt.Parse()
// If invalid flags or --help/-h, args := getopt.Args()
if err != nil {
// Print usage
fmt.Print(parser.Usage(err))
os.Exit(0)
}
if *cmdflag == "" || *interactiveflag { if *cmdflag != "" || *interactiveflag {
interactive = true interactive = true
} }
@ -120,6 +96,13 @@ func main() {
readline.LoadHistory(homedir + "/.hilbish-history") readline.LoadHistory(homedir + "/.hilbish-history")
RunInput(*cmdflag) RunInput(*cmdflag)
if len(args) > 0 {
err := l.DoFile(args[0])
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
for interactive { for interactive {
running = false running = false