-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgrove.go
122 lines (102 loc) · 3.07 KB
/
grove.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Grove - Git self-hosting for developers
//
// Copyright ⓒ 2013 Alexander Bauer and Luke Evers (GPLv3)
package main
import (
"flag"
"github.com/inhies/go-utils/log"
_ "log"
"os"
"path"
)
var (
Version = "0.5.12"
Bind = "0.0.0.0" // Interface to bind to
Port = "8860" // Port to bind to
Resources = "/usr/local/share/grove" // Directory to store resources in
Prefix = "" // Prefix to use in links
Theme = "light" // Default CSS to use
LogLevel log.LogLevel = log.INFO // Default log level
)
var (
l *log.Logger
user string // git username
)
const (
usage = "usage: %s [repositorydir]\n"
)
var (
fQuiet = flag.Bool("q", false, "disable logging output")
// fVerbose = flag.Bool("v", false, "enable verbose output")
fDebug = flag.Bool("debug", false, "enable debugging output")
fBind = flag.String("bind", Bind, "interface to bind to")
fPort = flag.String("port", Port, "port to listen on")
fRes = flag.String("res", Resources, "resources directory")
fPrefix = flag.String("prefix", Prefix, "prefix to use in links")
fWeb = flag.Bool("web", true, "enable web browsing")
fTheme = flag.String("theme", Theme, "use a particular theme")
fShowVersion = flag.Bool("version", false, "print major version and exit")
fShowFVersion = flag.Bool("version-full", false, "print full version and exit")
fShowBind = flag.Bool("show-bind", false, "print default bind interface and exit")
fShowPort = flag.Bool("show-port", false, "print default port and exit")
fShowRes = flag.Bool("show-res", false, "print default resources directory and exit")
)
func main() {
flag.Parse()
// Open a new logger with an appropriate log level.
if *fQuiet {
LogLevel = -1 // Disable ALL output
// } else if *fVerbose {
// LogLevel = log.INFO
} else if *fDebug {
LogLevel = log.DEBUG
}
l, _ = log.NewLevel(LogLevel, true, os.Stdout, "", log.Ltime)
// If any of the 'show' flags are set, print the relevant variable
// and exit.
switch {
case *fShowVersion:
l.Println(Version)
return
case *fShowFVersion:
l.Println(Version)
return
case *fShowBind:
l.Println(Bind)
return
case *fShowPort:
l.Println(Port)
return
case *fShowRes:
l.Println(Resources)
return
}
l.Infof("Starting Grove version %s\n", Version)
// Determine the directory to serve.
var repodir string
if flag.NArg() > 0 {
repodir = path.Clean(flag.Arg(0))
if !path.IsAbs(repodir) {
wd, err := os.Getwd()
if err != nil {
l.Fatalf("Error getting working directory: %s\n", err)
}
repodir = path.Join(wd, repodir)
}
} else {
wd, err := os.Getwd()
if err != nil {
l.Fatalf("Error getting working directory: %s\n", err)
}
repodir = wd
}
// Check to make sure that the CSS style is available, and exit if
// not.
fi, err := os.Stat(path.Join(*fRes, "/themes/", *fTheme+".css"))
if err != nil {
l.Fatalf("Theme %q could not be loaded: %s", *fTheme, err)
} else if fi.IsDir() == true {
l.Fatalf("Theme %q could not be loaded: is a directory\n", *fTheme)
}
Serve(repodir)
}