-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Flags.go
98 lines (86 loc) · 2.55 KB
/
Flags.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
package config
import (
"math"
"time"
)
const (
// DefaultRefreshRate represents the refresh interval.
DefaultRefreshRate = 1 * time.Second
// DefaultLogLevel represents the default log level.
DefaultLogLevel = "info"
// DefaultPortNum represents the default port number.
DefaultPortNum = 8080
// DefaultAddress represents the default address.
DefaultAddress = "localhost"
// DefaultLogLength represents the default log length.
DefaultLogLength = 1000
// DefaultSortColumn represents the default sort column.
DefaultSortColumn = "NAME"
// DefaultThemeName represents the default theme
DefaultThemeName = "Default"
)
const (
EnvVarNamePort = "PC_PORT_NUM"
EnvVarNameTui = "PC_DISABLE_TUI"
EnvVarNameConfig = "PC_CONFIG_FILES"
EnvVarNameNoServer = "PC_NO_SERVER"
EnvVarUnixSocketPath = "PC_SOCKET_PATH"
EnvVarReadOnlyMode = "PC_READ_ONLY"
)
// Flags represents PC configuration flags.
type Flags struct {
RefreshRate *time.Duration
PortNum *int
Address *string
LogLevel *string
LogFile *string
LogLength *int
LogFollow *bool
LogTailLength *int
IsTuiEnabled *bool
Command *string
Write *bool
NoDependencies *bool
HideDisabled *bool
SortColumn *string
SortColumnChanged bool
IsReverseSort *bool
NoServer *bool
KeepTuiOn *bool
IsOrderedShutDown *bool
PcTheme *string
PcThemeChanged bool
UnixSocketPath *string
IsUnixSocket *bool
IsReadOnlyMode *bool
OutputFormat *string
}
// NewFlags returns new configuration flags.
func NewFlags() *Flags {
return &Flags{
RefreshRate: toPtr(DefaultRefreshRate),
IsTuiEnabled: toPtr(getDisableTuiDefault()),
PortNum: toPtr(getPortDefault()),
Address: toPtr(DefaultAddress),
LogLength: toPtr(DefaultLogLength),
LogLevel: toPtr(DefaultLogLevel),
LogFile: toPtr(GetLogFilePath()),
LogFollow: toPtr(false),
LogTailLength: toPtr(math.MaxInt),
NoDependencies: toPtr(false),
HideDisabled: toPtr(false),
SortColumn: toPtr(DefaultSortColumn),
IsReverseSort: toPtr(false),
NoServer: toPtr(getNoServerDefault()),
KeepTuiOn: toPtr(false),
IsOrderedShutDown: toPtr(false),
PcTheme: toPtr(DefaultThemeName),
UnixSocketPath: toPtr(""),
IsUnixSocket: toPtr(false),
IsReadOnlyMode: toPtr(getReadOnlyDefault()),
OutputFormat: toPtr(""),
}
}
func toPtr[T any](t T) *T {
return &t
}