50 lines
903 B
Go
50 lines
903 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
lox "git.geekproject.eu/halfdan/glox/lox"
|
|
)
|
|
|
|
// glox:
|
|
// run - run a scripts
|
|
// build - build a binary
|
|
// fmt - format file
|
|
// sh - run interactive shell
|
|
func main() {
|
|
if len(os.Args) < 2 {
|
|
usage()
|
|
}
|
|
|
|
switch os.Args[1] {
|
|
case "run":
|
|
if len(os.Args) < 3 {
|
|
fmt.Print("glox run: no lox file listed\n")
|
|
os.Exit(2)
|
|
}
|
|
lox.RunFile(os.Args[2])
|
|
case "fmt":
|
|
if len(os.Args) < 3 {
|
|
fmt.Print("glox fmt: no lox file listed\n")
|
|
os.Exit(2)
|
|
}
|
|
lox.RunFormat(os.Args[2])
|
|
case "sh":
|
|
lox.RunPrompt()
|
|
default:
|
|
usage()
|
|
}
|
|
}
|
|
|
|
func usage() {
|
|
fmt.Print("glox is a tool for running Lox code.\n\n")
|
|
fmt.Print("Usage:\n\n")
|
|
fmt.Print("\tglox <command> [arguments]\n\n")
|
|
fmt.Print("The commands are:\n\n")
|
|
fmt.Print("\trun\trun a lox script\n")
|
|
fmt.Print("\tfmt\tformat input file\n")
|
|
fmt.Print("\tsh\tstart interactive shell\n\n")
|
|
os.Exit(2)
|
|
}
|