-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolarwind.go
73 lines (63 loc) · 1.6 KB
/
solarwind.go
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
69
70
71
72
73
package main
import (
"log"
"os"
"path"
"path/filepath"
"github.com/mitchellh/cli"
)
var (
CurrentPath string
DefaultContentDir string
DefaultPostsDir string
DefaultDestinationDir string
DefaultTemplateDir string
DefaultSolarwindfilePath string
DefaultStaticDir string
)
const Solarwindfile = "Solarwindfile"
func init() {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
CurrentPath = dir
DefaultContentDir = path.Join(dir, "content")
DefaultPostsDir = path.Join(DefaultContentDir, "posts")
DefaultDestinationDir = path.Join(CurrentPath, "public")
DefaultTemplateDir = path.Join(dir, "templates")
DefaultSolarwindfilePath = path.Join(CurrentPath, Solarwindfile)
DefaultStaticDir = path.Join(CurrentPath, "static")
// Sanity check. Make sure a couple of these things exist
for _, node := range []string{DefaultSolarwindfilePath, DefaultContentDir, DefaultPostsDir, DefaultTemplateDir} {
if _, err := os.Stat(node); err != nil {
if os.IsNotExist(err) {
log.Fatalf("%s does not exist. It must exist to continue generating a site.", node)
} else {
panic(err)
}
}
}
}
func main() {
c := cli.NewCLI("nbsssg", "0.1.0")
ui := &cli.BasicUi{Writer: os.Stdout}
c.Args = os.Args[1:]
c.Commands = map[string]cli.CommandFactory{
"generate": func() (cli.Command, error) {
return &GenerateCommand{
Ui: ui,
}, nil
},
"server": func() (cli.Command, error) {
return &ServerCommand{
Ui: ui,
}, nil
},
}
exitCode, err := c.Run()
if err != nil {
log.Println(err)
}
os.Exit(exitCode)
}