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