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
|
package main
import (
"flag"
"os"
"path/filepath"
"runtime"
"text/template"
)
type UsageArgs struct {
Version string
BuildDate string
OS string
Arch string
DefaultDataDir string
}
var usageTmpl = `usage: grumble [options]
grumble {{.Version}} ({{.BuildDate}})
target: {{.OS}}, {{.Arch}}
--help
Shows this help listing.
--datadir <data-dir> (default: {{.DefaultDataDir}})
Directory to use for server storage.
--log <log-path> (default: $DATADIR/grumble.log)
Log file path.
--regen-keys
Force grumble to regenerate its global RSA
keypair (and certificate).
The global keypair lives in the root of the
grumble data directory.
--import-murmurdb <murmur-sqlite-path>
Import a Murmur SQLite database into grumble.
Use the --cleanup argument to force grumble to
clean up its data directory when doing the
import. This is *DESTRUCTIVE*! Use with care.
`
type args struct {
ShowHelp bool
DataDir string
LogPath string
RegenKeys bool
SQLiteDB string
CleanUp bool
}
func defaultDataDir() string {
homedir := os.Getenv("HOME")
dirname := ".grumble"
if runtime.GOOS == "windows" {
homedir = os.Getenv("USERPROFILE")
}
return filepath.Join(homedir, dirname)
}
func defaultLogPath() string {
return filepath.Join(defaultDataDir(), "grumble.log")
}
func Usage() {
t, err := template.New("usage").Parse(usageTmpl)
if err != nil {
panic("unable to parse usage template")
}
err = t.Execute(os.Stdout, UsageArgs{
Version: version,
BuildDate: buildDate,
OS: runtime.GOOS,
Arch: runtime.GOARCH,
DefaultDataDir: defaultDataDir(),
})
if err != nil {
panic("unable to execute usage template")
}
}
var Args args
func init() {
flag.Usage = Usage
flag.BoolVar(&Args.ShowHelp, "help", false, "")
flag.StringVar(&Args.DataDir, "datadir", defaultDataDir(), "")
flag.StringVar(&Args.LogPath, "log", defaultLogPath(), "")
flag.BoolVar(&Args.RegenKeys, "regen-keys", false, "")
flag.StringVar(&Args.SQLiteDB, "import-murmurdb", "", "")
flag.BoolVar(&Args.CleanUp, "cleanup", false, "")
}
|