jorge/main.go

55 lines
953 B
Go
Raw Normal View History

2024-02-09 16:04:40 +01:00
package main
import (
"errors"
2024-02-09 16:04:40 +01:00
"fmt"
"os"
2024-02-16 19:29:43 +01:00
"github.com/facundoolano/jorge/commands"
2024-02-09 16:04:40 +01:00
)
func main() {
2024-02-10 15:37:38 +01:00
err := run(os.Args)
if err != nil {
fmt.Println("error:", err)
os.Exit(1)
}
}
func run(args []string) error {
2024-02-09 17:50:52 +01:00
// TODO consider using cobra or something else to make cli more declarative
// and get a better ux out of the box
2024-02-09 16:04:40 +01:00
if len(os.Args) < 2 {
2024-02-09 17:50:52 +01:00
// TODO print usage
2024-02-10 15:37:38 +01:00
return errors.New("expected subcommand")
2024-02-09 16:04:40 +01:00
}
switch os.Args[1] {
case "init":
if len(os.Args) < 3 {
return errors.New("project directory missing")
}
rootDir := os.Args[2]
return commands.Init(rootDir)
2024-02-09 16:04:40 +01:00
case "build":
2024-02-15 16:38:17 +01:00
rootDir := "."
if len(os.Args) > 2 {
rootDir = os.Args[2]
}
return commands.Build(rootDir)
2024-02-09 16:04:40 +01:00
case "new":
return commands.New()
2024-02-09 16:04:40 +01:00
case "serve":
rootDir := "."
if len(os.Args) > 2 {
rootDir = os.Args[2]
}
return commands.Serve(rootDir)
2024-02-09 16:04:40 +01:00
default:
2024-02-09 17:50:52 +01:00
// TODO print usage
2024-02-10 15:37:38 +01:00
return errors.New("unknown subcommand")
2024-02-09 22:09:42 +01:00
}
2024-02-09 16:04:40 +01:00
}