main.go (view raw)
1package main
2
3import (
4 "fmt"
5 "os"
6
7 "git.icyphox.sh/vite/commands"
8)
9
10func main() {
11 args := os.Args
12
13 helpStr := `usage: vite [options]
14
15A simple and minimal static site generator.
16
17options:
18 init PATH create vite project at PATH
19 build [--drafts] builds the current project
20 new PATH create a new markdown post
21 serve [HOST:PORT] serves the 'build' directory
22`
23
24 if len(args) <= 1 {
25 fmt.Println(helpStr)
26 return
27 }
28
29 switch args[1] {
30 case "init":
31 if len(args) <= 2 {
32 fmt.Println(helpStr)
33 return
34 }
35 initPath := args[2]
36 if err := commands.Init(initPath); err != nil {
37 fmt.Fprintf(os.Stderr, "error: init: %+v\n", err)
38 }
39
40 case "build":
41 var drafts bool
42 if len(args) > 2 && args[2] == "--drafts" {
43 drafts = true
44 }
45 if err := commands.Build(drafts); err != nil {
46 fmt.Fprintf(os.Stderr, "error: build: %+v\n", err)
47 }
48
49 case "new":
50 if len(args) <= 2 {
51 fmt.Println(helpStr)
52 return
53 }
54 newPath := args[2]
55 if err := commands.New(newPath); err != nil {
56 fmt.Fprintf(os.Stderr, "error: new: %+v\n", err)
57 }
58 case "serve":
59 var addr string
60 if len(args) == 3 {
61 addr = args[2]
62 } else {
63 addr = ":9191"
64 }
65 if err := commands.Serve(addr); err != nil {
66 fmt.Fprintf(os.Stderr, "error: serve: %+v\n", err)
67 }
68 default:
69 fmt.Println(helpStr)
70 }
71
72}