59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"local/args"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
Repeat bool
|
|
Stopwatch bool
|
|
ETA bool
|
|
TS bool
|
|
Done bool
|
|
Duration time.Duration
|
|
Offset time.Duration
|
|
Msg string
|
|
Interval time.Duration
|
|
Until time.Time
|
|
}
|
|
|
|
func NewConfig() (Config, error) {
|
|
as := args.NewArgSet()
|
|
|
|
as.Append(args.TIME, "until", "deadline", time.Time{})
|
|
as.Append(args.BOOL, "repeat", "whether to loop", true)
|
|
as.Append(args.BOOL, "stopwatch", "count up to time instead of down", false)
|
|
as.Append(args.BOOL, "eta", "whether to display deadline", false)
|
|
as.Append(args.BOOL, "ts", "whether to display timestamp", false)
|
|
as.Append(args.BOOL, "done", "whether to display done or not", false)
|
|
as.Append(args.DURATION, "duration", "how long the base time is", time.Minute*30)
|
|
as.Append(args.DURATION, "offset", "offset from the base time", time.Second*0)
|
|
as.Append(args.STRING, "msg", "message to display", "Timer up")
|
|
as.Append(args.DURATION, "interval", "refresh interval", time.Millisecond*500)
|
|
|
|
if err := as.Parse(); err != nil {
|
|
return Config{}, err
|
|
}
|
|
|
|
config := Config{
|
|
Repeat: as.Get("repeat").GetBool(),
|
|
Stopwatch: as.Get("stopwatch").GetBool(),
|
|
ETA: as.Get("eta").GetBool(),
|
|
TS: as.Get("ts").GetBool(),
|
|
Done: as.Get("done").GetBool(),
|
|
Duration: as.Get("duration").GetDuration(),
|
|
Offset: as.Get("offset").GetDuration(),
|
|
Msg: as.Get("msg").GetString(),
|
|
Interval: as.Get("interval").GetDuration(),
|
|
Until: as.Get("until").GetTime(),
|
|
}
|
|
|
|
if !config.Until.IsZero() {
|
|
config.Repeat = false
|
|
config.Duration = time.Until(config.Until) + config.Offset
|
|
}
|
|
|
|
return config, nil
|
|
}
|