-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (48 loc) · 1.08 KB
/
main.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
package main
// This file implements the main function
import (
"flag"
"mjolnir/helheim"
"mjolnir/midgard"
"os"
"path"
)
// Command-line flags for special modes
// not normally used by the user.
var (
flag_daemon = flag.Bool("d", false, "run in daemon mode")
flag_version = flag.Bool("v", false, "show version and exit")
flag_port = flag.String("p", ":2527", "TCP port")
)
func main() {
flag.Parse()
midgard.ProgName = "mjolnir"
midgard.Port = *flag_port
// Daemon mode: enter the realm of the daemons
if *flag_daemon {
helheim.MainDaemon()
return
}
// Client mode: stay in the realm of the humans
args := flag.Args()
if len(args) > 1 {
if args[0] == "add" || args[0] == "rm" || args[0] == "requeue" {
ExpandFiles(args[1:])
}
}
midgard.MainClient(args)
}
// Make file paths absolute.
func ExpandFiles(args []string) {
wd, err := os.Getwd()
helheim.Check(err)
for i, arg := range args {
if !path.IsAbs(arg) && FileExists(arg) {
args[i] = path.Clean(wd + "/" + arg)
}
}
}
func FileExists(file string) bool {
_, err := os.Stat(file)
return err == nil
}