mirror of
https://github.com/facundoolano/jorge.git
synced 2024-12-26 21:58:51 +01:00
20150cf7a3
* rename command to post * initial jorge post implementation * fixes * update comment * move funs around * move default front matter to constants * more docs * tweak defaults line breaks
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/facundoolano/jorge/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
|
|
|
|
if len(os.Args) < 2 {
|
|
// TODO print usage
|
|
return errors.New("expected subcommand")
|
|
}
|
|
|
|
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)
|
|
case "build":
|
|
rootDir := "."
|
|
if len(os.Args) > 2 {
|
|
rootDir = os.Args[2]
|
|
}
|
|
return commands.Build(rootDir)
|
|
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)
|
|
case "serve":
|
|
rootDir := "."
|
|
if len(os.Args) > 2 {
|
|
rootDir = os.Args[2]
|
|
}
|
|
return commands.Serve(rootDir)
|
|
default:
|
|
// TODO print usage
|
|
return errors.New("unknown subcommand")
|
|
}
|
|
}
|