jorge/main.go
2024-02-10 11:37:38 -03:00

48 lines
847 B
Go

package main
import (
"errors"
"flag"
"fmt"
"os"
"github.com/facundoolano/blorg/commands"
)
func main() {
err := run(os.Args)
if err != nil {
fmt.Println("error:", err)
os.Exit(1)
}
}
func run(args []string) error {
// TODO consider using cobra or something else to make cli more declarative
// and get a better ux out of the box
initCmd := flag.NewFlagSet("init", flag.ExitOnError)
newCmd := flag.NewFlagSet("new", flag.ExitOnError)
if len(os.Args) < 2 {
// TODO print usage
return errors.New("expected subcommand")
}
switch os.Args[1] {
case "init":
initCmd.Parse(os.Args[2:])
commands.Init()
case "build":
commands.Build()
case "new":
newCmd.Parse(os.Args[2:])
commands.New()
case "serve":
commands.Serve()
default:
// TODO print usage
return errors.New("unknown subcommand")
}
return nil
}