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
|
|
|
"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
|
|
|
|
|
|
|
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":
|
2024-02-17 21:09:19 +01:00
|
|
|
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-21 16:56:22 +01:00
|
|
|
case "post":
|
|
|
|
var title string
|
|
|
|
if len(os.Args) >= 3 {
|
|
|
|
title = os.Args[2]
|
|
|
|
} else {
|
|
|
|
title = commands.Prompt("title")
|
|
|
|
}
|
|
|
|
rootDir := "."
|
|
|
|
return commands.Post(rootDir, title)
|
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
|
|
|
}
|