Skip to content

Commit 3f5bbc4

Browse files
authored
feat: add flag categories (#260)
1 parent 0d22ee4 commit 3f5bbc4

4 files changed

Lines changed: 82 additions & 53 deletions

File tree

log.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,29 @@ const (
1515
FlagLogCtx = "log.ctx"
1616
)
1717

18+
// CategoryLog is the log flag category.
19+
var CategoryLog = "Logging"
20+
1821
// LogFlags are flags that configure logging.
1922
var LogFlags = Flags{
2023
&cli.StringFlag{
21-
Name: FlagLogFormat,
22-
Usage: "Specify the format of logs. Supported formats: 'logfmt', 'json', 'console'",
23-
EnvVars: []string{"LOG_FORMAT"},
24+
Name: FlagLogFormat,
25+
Category: CategoryLog,
26+
Usage: "Specify the format of logs. Supported formats: 'logfmt', 'json', 'console'",
27+
EnvVars: []string{"LOG_FORMAT"},
2428
},
2529
&cli.StringFlag{
26-
Name: FlagLogLevel,
27-
Value: "info",
28-
Usage: "Specify the log level. e.g. 'trace', 'debug', 'info', 'error'.",
29-
EnvVars: []string{"LOG_LEVEL"},
30+
Name: FlagLogLevel,
31+
Category: CategoryLog,
32+
Value: "info",
33+
Usage: "Specify the log level. e.g. 'trace', 'debug', 'info', 'error'.",
34+
EnvVars: []string{"LOG_LEVEL"},
3035
},
3136
&cli.StringSliceFlag{
32-
Name: FlagLogCtx,
33-
Usage: "A list of context field appended to every log. Format: key=value.",
34-
EnvVars: []string{"LOG_CTX"},
37+
Name: FlagLogCtx,
38+
Category: CategoryLog,
39+
Usage: "A list of context field appended to every log. Format: key=value.",
40+
EnvVars: []string{"LOG_CTX"},
3541
},
3642
}
3743

profile.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,36 @@ const (
3232
FlagProfilingTypes = "profiling.types"
3333
)
3434

35+
// CategoryProfiling is the profiling category.
36+
var CategoryProfiling = "Profiling"
37+
3538
// ProfilingFlags are flags that configure profiling.
3639
var ProfilingFlags = Flags{
3740
&cli.StringFlag{
38-
Name: FlagProfilingDSN,
41+
Name: FlagProfilingDSN,
42+
Category: CategoryProfiling,
3943
Usage: "The address to the Pyroscope server, in the format " +
4044
"'http://basic:auth@server:port?token=auth-token&tenantid=tenant-id'.",
4145
EnvVars: []string{"PROFILING_DSN"},
4246
},
4347
&cli.DurationFlag{
44-
Name: FlagProfileUploadRate,
45-
Usage: "The rate at which profiles are uploaded.",
46-
Value: 15 * time.Second,
47-
EnvVars: []string{"PROFILING_UPLOAD_RATE"},
48+
Name: FlagProfileUploadRate,
49+
Category: CategoryProfiling,
50+
Usage: "The rate at which profiles are uploaded.",
51+
Value: 15 * time.Second,
52+
EnvVars: []string{"PROFILING_UPLOAD_RATE"},
4853
},
4954
&cli.StringSliceFlag{
50-
Name: FlagProfilingTags,
51-
Usage: "A list of tags appended to every profile. Format: key=value.",
52-
EnvVars: []string{"PROFILING_TAGS"},
55+
Name: FlagProfilingTags,
56+
Category: CategoryProfiling,
57+
Usage: "A list of tags appended to every profile. Format: key=value.",
58+
EnvVars: []string{"PROFILING_TAGS"},
5359
},
5460
&cli.StringSliceFlag{
55-
Name: FlagProfilingTypes,
56-
Usage: "The type of profiles to include. Defaults to all.",
57-
EnvVars: []string{"PROFILING_TYPES"},
61+
Name: FlagProfilingTypes,
62+
Category: CategoryProfiling,
63+
Usage: "The type of profiles to include. Defaults to all.",
64+
EnvVars: []string{"PROFILING_TYPES"},
5865
},
5966
}
6067

stats.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,35 @@ const (
2626
FlagStatsTags = "stats.tags"
2727
)
2828

29+
// CategoryStats is the stats flag category.
30+
var CategoryStats = "Stats"
31+
2932
// StatsFlags are flags that configure stats.
3033
var StatsFlags = Flags{
3134
&cli.StringFlag{
32-
Name: FlagStatsDSN,
33-
Usage: "The DSN of a stats backend.",
34-
EnvVars: []string{"STATS_DSN"},
35+
Name: FlagStatsDSN,
36+
Category: CategoryStats,
37+
Usage: "The DSN of a stats backend.",
38+
EnvVars: []string{"STATS_DSN"},
3539
},
3640
&cli.DurationFlag{
37-
Name: FlagStatsInterval,
38-
Usage: "The frequency at which the stats are reported.",
39-
Value: time.Second,
40-
EnvVars: []string{"STATS_INTERVAL"},
41+
Name: FlagStatsInterval,
42+
Category: CategoryStats,
43+
Usage: "The frequency at which the stats are reported.",
44+
Value: time.Second,
45+
EnvVars: []string{"STATS_INTERVAL"},
4146
},
4247
&cli.StringFlag{
43-
Name: FlagStatsPrefix,
44-
Usage: "The prefix of the measurements names.",
45-
EnvVars: []string{"STATS_PREFIX"},
48+
Name: FlagStatsPrefix,
49+
Category: CategoryStats,
50+
Usage: "The prefix of the measurements names.",
51+
EnvVars: []string{"STATS_PREFIX"},
4652
},
4753
&cli.StringSliceFlag{
48-
Name: FlagStatsTags,
49-
Usage: "A list of tags appended to every measurement. Format: key=value.",
50-
EnvVars: []string{"STATS_TAGS"},
54+
Name: FlagStatsTags,
55+
Category: CategoryStats,
56+
Usage: "A list of tags appended to every measurement. Format: key=value.",
57+
EnvVars: []string{"STATS_TAGS"},
5158
},
5259
}
5360

trace.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,47 @@ const (
2626
FlagTracingRatio = "tracing.ratio"
2727
)
2828

29+
// CategoryTracing is the tracing flag category.
30+
var CategoryTracing = "Tracing"
31+
2932
// TracingFlags are flags that configure tracing.
3033
var TracingFlags = Flags{
3134
&cli.StringFlag{
32-
Name: FlagTracingExporter,
33-
Usage: "The tracing backend. Supported: 'zipkin', 'otlphttp', 'otlpgrpc'.",
34-
EnvVars: []string{"TRACING_EXPORTER"},
35+
Name: FlagTracingExporter,
36+
Category: CategoryTracing,
37+
Usage: "The tracing backend. Supported: 'zipkin', 'otlphttp', 'otlpgrpc'.",
38+
EnvVars: []string{"TRACING_EXPORTER"},
3539
},
3640
&cli.StringFlag{
37-
Name: FlagTracingEndpoint,
38-
Usage: "The tracing backend endpoint.",
39-
EnvVars: []string{"TRACING_ENDPOINT"},
41+
Name: FlagTracingEndpoint,
42+
Category: CategoryTracing,
43+
Usage: "The tracing backend endpoint.",
44+
EnvVars: []string{"TRACING_ENDPOINT"},
4045
},
4146
&cli.BoolFlag{
42-
Name: FlagTracingEndpointInsecure,
43-
Usage: "Determines if the endpoint is insecure.",
44-
EnvVars: []string{"TRACING_ENDPOINT_INSECURE"},
47+
Name: FlagTracingEndpointInsecure,
48+
Category: CategoryTracing,
49+
Usage: "Determines if the endpoint is insecure.",
50+
EnvVars: []string{"TRACING_ENDPOINT_INSECURE"},
4551
},
4652
&cli.StringSliceFlag{
47-
Name: FlagTracingTags,
48-
Usage: "A list of tags appended to every trace. Format: key=value.",
49-
EnvVars: []string{"TRACING_TAGS"},
53+
Name: FlagTracingTags,
54+
Category: CategoryTracing,
55+
Usage: "A list of tags appended to every trace. Format: key=value.",
56+
EnvVars: []string{"TRACING_TAGS"},
5057
},
5158
&cli.StringSliceFlag{
52-
Name: FlagTracingHeaders,
53-
Usage: "A list of headers appended to every trace when supported by the exporter. Format: key=value.",
54-
EnvVars: []string{"TRACING_HEADERS"},
59+
Name: FlagTracingHeaders,
60+
Category: CategoryTracing,
61+
Usage: "A list of headers appended to every trace when supported by the exporter. Format: key=value.",
62+
EnvVars: []string{"TRACING_HEADERS"},
5563
},
5664
&cli.Float64Flag{
57-
Name: FlagTracingRatio,
58-
Usage: "The ratio between 0 and 1 of sample traces to take.",
59-
Value: 0.5,
60-
EnvVars: []string{"TRACING_RATIO"},
65+
Name: FlagTracingRatio,
66+
Category: CategoryTracing,
67+
Usage: "The ratio between 0 and 1 of sample traces to take.",
68+
Value: 0.5,
69+
EnvVars: []string{"TRACING_RATIO"},
6170
},
6271
}
6372

0 commit comments

Comments
 (0)