summaryrefslogtreecommitdiff
path: root/internal/config/read.go
blob: ea358f8b3eeefe8f084dd1c7d133e1cd4e20875c (plain)
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
package config

import (
	"os"
)

// Read the DTail configuration.
func Read(configFile string, sshPort int, noColor bool) {
	initializer := configInitializer{
		Common: newDefaultCommonConfig(),
		Server: newDefaultServerConfig(),
		Client: newDefaultClientConfig(),
	}

	if configFile == "" {
		configFile = "./cfg/dtail.json"
	}

	if _, err := os.Stat(configFile); !os.IsNotExist(err) {
		initializer.parseConfig(configFile)
	}

	// Assign pointers to global variables, so that we can access the
	// configuration from any place of the program.
	Common = initializer.Common
	Server = initializer.Server
	Client = initializer.Client

	if Server.MapreduceLogFormat == "" {
		Server.MapreduceLogFormat = "default"
	}

	// If non-standard port specified, overwrite config
	if sshPort != 2222 {
		Common.SSHPort = sshPort
	}
	if noColor {
		Client.TermColorsEnable = false
	}
}