-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
66 lines (53 loc) · 1.89 KB
/
options.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
package main
import (
"flag"
"os"
"path/filepath"
"runtime"
"time"
)
type Options struct {
ConfigDir string
LogFile string
IdleTimeoutInSeconds int
IdleTimeout time.Duration
Version bool
Verbose bool
Pprof string
NetTimeout int64
DefaultFileDeadtime string
DefaultExcludeFileFilter string
}
func (options *Options) ParseArguments() {
options.NetTimeout = 15
options.DefaultFileDeadtime = "360h"
options.DefaultExcludeFileFilter = "((.gz)|(.zip)|(.tar)|(.zip))"
flag.StringVar(&options.ConfigDir, "config-dir", options.ConfigDir, "path to dhound-agent configuration directory")
flag.StringVar(&options.LogFile, "log-file", options.LogFile, "path to the dhound log file")
flag.IntVar(&options.IdleTimeoutInSeconds, "timeout", 60, "frequency in seconds to send data on the server")
flag.BoolVar(&options.Verbose, "verbose", options.Verbose, "log more detailed and debug information")
flag.BoolVar(&options.Version, "version", options.Version, "dhound-agent version")
flag.StringVar(&options.Pprof, "pprof", options.Pprof, "profiling option (for internal using)")
flag.Parse()
if runtime.GOOS == "windows" {
// for windows all files are located on the same folder, current directory should be set up in the code
execPath, err := Executable()
if err != nil {
exit(exitStat.faulted, "failed receiving current executable path. error: %s\n", err)
return
}
workingDir := filepath.Dir(execPath)
// set current working directory
err = os.Chdir(workingDir)
if err != nil {
exit(exitStat.faulted, "failed settings working dir. error: %s\n", err)
return
}
if len(options.ConfigDir) < 1 {
options.ConfigDir = "config"
}
}
if options.IdleTimeoutInSeconds > 0 {
options.IdleTimeout = time.Second * time.Duration(options.IdleTimeoutInSeconds)
}
}