@@ -25,8 +25,8 @@ import (
25
25
)
26
26
27
27
const (
28
- TimeFormat12H = "12h"
29
- TimeFormat24H = "24h"
28
+ timeFormat12H = "12h"
29
+ timeFormat24H = "24h"
30
30
)
31
31
32
32
type Config struct {
@@ -106,7 +106,7 @@ var RawDefault = struct {
106
106
HTTPPort uint16 `koanf:"http.port"`
107
107
// IMAPPort uint16 `koanf:"imap.port"`
108
108
}{
109
- TimeFormat : TimeFormat12H ,
109
+ TimeFormat : timeFormat12H ,
110
110
SMTPMaxPayloadSize : "25 MB" ,
111
111
DataDirectory : "smtpbridge_data" ,
112
112
PythonExecutable : "python3" ,
@@ -115,15 +115,17 @@ var RawDefault = struct {
115
115
// IMAPPort: 10143,
116
116
}
117
117
118
+ // flagFlatKeys are remaps of CLI flag keys to work with koanf's parsing.
118
119
var flagFlatKeys map [string ]string = map [string ]string {
119
120
"time-format" : "time_format" ,
120
121
"data-directory" : "data_directory" ,
121
122
"python-executable" : "python_executable" ,
122
123
}
123
124
125
+ // WithFlagSet includes CLI flags with the config reading.
124
126
func WithFlagSet (flags * flag.FlagSet ) * flag.FlagSet {
125
127
flags .String ("config" , "" , flagUsageString ("" , "Path to config file." ))
126
- flags .String ("time-format" , "" , flagUsageString (TimeFormat12H , fmt .Sprintf ("Format for time display (%s/%s)." , TimeFormat12H , TimeFormat24H )))
128
+ flags .String ("time-format" , "" , flagUsageString (timeFormat12H , fmt .Sprintf ("Format for time display (%s/%s)." , timeFormat12H , timeFormat24H )))
127
129
flags .String ("data-directory" , "" , flagUsageString (RawDefault .DataDirectory , "Path to data directory." ))
128
130
flags .String ("python-executable" , "" , flagUsageString (RawDefault .PythonExecutable , "Python executable." ))
129
131
flags .Bool ("debug" , false , flagUsageBool (false , "Run in debug mode." ))
@@ -290,9 +292,9 @@ func (p Parser) Parse(raw Raw) (Config, error) {
290
292
291
293
var timeHourFormat string
292
294
switch raw .TimeFormat {
293
- case TimeFormat12H :
295
+ case timeFormat12H :
294
296
timeHourFormat = helpers .TimeHourFormat12
295
- case TimeFormat24H :
297
+ case timeFormat24H :
296
298
timeHourFormat = helpers .TimeHourFormat24
297
299
default :
298
300
return Config {}, fmt .Errorf ("invalid time format: %s" , raw .TimeFormat )
0 commit comments