all repos — vite @ 02c90b752aeecafd7c76262990e3a5e4b08bb446

a fast (this time, actually) and minimal static site generator

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                       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		if err := commands.Build(); err != nil {
42			fmt.Fprintf(os.Stderr, "error: build: %+v\n", err)
43		}
44
45	case "new":
46		if len(args) <= 2 {
47			fmt.Println(helpStr)
48			return
49		}
50		newPath := args[2]
51		if err := commands.New(newPath); err != nil {
52			fmt.Fprintf(os.Stderr, "error: new: %+v\n", err)
53		}
54	case "serve":
55		var addr string
56		if len(args) == 3 {
57			addr = args[2]
58		} else {
59			addr = ":9191"
60		}
61		if err := commands.Serve(addr); err != nil {
62			fmt.Fprintf(os.Stderr, "error: serve: %+v\n", err)
63		}
64	default:
65		fmt.Println(helpStr)
66	}
67
68}