2024-02-09 16:04:40 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-09 20:38:16 +01:00
|
|
|
"errors"
|
2024-02-09 16:04:40 +01:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2024-02-09 20:38:16 +01:00
|
|
|
|
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
|
|
|
initCmd := flag.NewFlagSet("init", flag.ExitOnError)
|
|
|
|
newCmd := flag.NewFlagSet("new", flag.ExitOnError)
|
|
|
|
|
|
|
|
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":
|
|
|
|
initCmd.Parse(os.Args[2:])
|
2024-02-11 17:16:10 +01:00
|
|
|
return commands.Init()
|
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":
|
|
|
|
newCmd.Parse(os.Args[2:])
|
2024-02-11 17:16:10 +01:00
|
|
|
return commands.New()
|
2024-02-09 16:04:40 +01:00
|
|
|
case "serve":
|
2024-02-16 16:39:19 +01:00
|
|
|
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
|
|
|
}
|