mirror of
https://codeberg.org/scip/ts.git
synced 2025-12-17 12:31:06 +01:00
make reference time configurable
This commit is contained in:
@@ -98,8 +98,8 @@ type Config struct {
|
||||
Mode int
|
||||
|
||||
// internal flags for [unit] tests
|
||||
tz string
|
||||
refTime time.Time
|
||||
tz string // has to be set directly in code
|
||||
refTime time.Time // must be set via env var $TSREFTIME
|
||||
}
|
||||
|
||||
func InitConfig(output io.Writer) (*Config, error) {
|
||||
@@ -134,11 +134,23 @@ func InitConfig(output io.Writer) (*Config, error) {
|
||||
}
|
||||
|
||||
// fetch values
|
||||
conf := &Config{Output: output}
|
||||
conf := &Config{Output: output, refTime: time.Now()}
|
||||
if err := kloader.Unmarshal("", &conf); err != nil {
|
||||
return nil, fmt.Errorf("error unmarshalling: %w", err)
|
||||
}
|
||||
|
||||
// check internal env var[s], if any
|
||||
reftime, present := os.LookupEnv("TSREFTIME")
|
||||
if present {
|
||||
// e.g: 2014-01-03T00:00:00+01:00
|
||||
ts, err := time.Parse(time.RFC3339Nano, reftime)
|
||||
if err != nil {
|
||||
os.Exit(Die("failed to set reference time from $TSREFTIME", err))
|
||||
}
|
||||
|
||||
conf.refTime = ts
|
||||
}
|
||||
|
||||
// want examples?
|
||||
if conf.Examples {
|
||||
_, err := fmt.Fprintln(output, Examples)
|
||||
|
||||
Reference in New Issue
Block a user