/
application_cli_flags.go
135 lines (130 loc) · 3.95 KB
/
application_cli_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright (c) 2022-2023 The Go-Curses Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
// You may obtain a copy of the license at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cdk
import (
"github.com/urfave/cli/v2"
"github.com/go-curses/cdk/log"
)
var (
AppCliProfileFlag = &cli.StringFlag{
Category: "Go-Curses",
Name: "cdk-profile",
EnvVars: []string{"GO_CDK_PROFILE"},
Usage: "profile one of: none, block, cpu, goroutine, mem, mutex, thread or trace",
DefaultText: "none",
}
AppCliProfilePathFlag = &cli.StringFlag{
Category: "Go-Curses",
Name: "cdk-profile-path",
EnvVars: []string{"GO_CDK_PROFILE_PATH"},
Usage: "specify the directory path to store the profile data",
DefaultText: DefaultGoProfilePath,
}
AppCliLogFileFlag = &cli.StringFlag{
Category: "Go-Curses",
Name: "cdk-log-file",
EnvVars: []string{"GO_CDK_LOG_FILE"},
Usage: "path to log file",
DefaultText: log.DefaultLogPath,
}
AppCliLogLevelFlag = &cli.StringFlag{
Category: "Go-Curses",
Name: "cdk-log-level",
EnvVars: []string{"GO_CDK_LOG_LEVEL"},
Value: "error",
Usage: "highest level of verbosity",
DefaultText: "error",
}
AppCliLogFormatFlag = &cli.StringFlag{
Category: "Go-Curses",
Name: "cdk-log-format",
EnvVars: []string{"GO_CDK_LOG_FORMAT"},
Value: "pretty",
Usage: "json, text or pretty",
DefaultText: "pretty",
}
AppCliLogTimestampsFlag = &cli.BoolFlag{
Category: "Go-Curses",
Name: "cdk-log-timestamps",
EnvVars: []string{"GO_CDK_LOG_TIMESTAMPS"},
Usage: "enable timestamps",
DefaultText: "false",
}
AppCliLogTimestampFormatFlag = &cli.StringFlag{
Category: "Go-Curses",
Name: "cdk-log-timestamp-format",
EnvVars: []string{"GO_CDK_LOG_TIMESTAMP_FORMAT"},
Value: log.DefaultTimestampFormat,
Usage: "timestamp format",
DefaultText: log.DefaultTimestampFormat,
}
AppCliLogFullPathsFlag = &cli.BoolFlag{
Category: "Go-Curses",
Name: "cdk-log-full-paths",
EnvVars: []string{"GO_CDK_LOG_FULL_PATHS"},
Usage: "log the full paths of source files",
DefaultText: "false",
}
AppCliLogOutputFlag = &cli.StringFlag{
Category: "Go-Curses",
Name: "cdk-log-output",
EnvVars: []string{"GO_CDK_LOG_OUTPUT"},
Value: "file",
Usage: "logging output type: stdout, stderr or file",
DefaultText: "file",
}
AppCliLogLevelsFlag = &cli.BoolFlag{
Category: "Go-Curses",
Name: "cdk-log-levels",
Usage: "list the levels of logging verbosity",
}
AppCliTtyFlag = &cli.StringFlag{
Category: "Go-Curses",
Name: "cdk-tty",
Usage: "specify the display tty",
EnvVars: []string{"GO_CDK_TTY"},
}
)
func GetApplicationCliFlags() (flags []cli.Flag) {
AppCliTtyFlag.Hidden = !Build.TtyFlag
flags = append(flags, AppCliTtyFlag)
if Build.Profiling {
flags = append(flags, AppCliProfileFlag, AppCliProfilePathFlag)
}
if Build.LogFile {
flags = append(flags, AppCliLogFileFlag)
}
if Build.LogFormat {
flags = append(flags, AppCliLogFormatFlag)
}
if Build.LogFullPaths {
flags = append(flags, AppCliLogFullPathsFlag)
}
if Build.LogLevel {
flags = append(flags, AppCliLogLevelFlag)
}
if Build.LogLevels {
flags = append(flags, AppCliLogLevelsFlag)
}
if Build.LogTimestampFormat {
flags = append(flags, AppCliLogTimestampFormatFlag)
}
if Build.LogTimestamps {
flags = append(flags, AppCliLogTimestampsFlag)
}
if Build.LogOutput {
flags = append(flags, AppCliLogOutputFlag)
}
return
}