48 lines
900 B
Go
48 lines
900 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
)
|
|
|
|
const defaultTimerPath = ".timer.toml"
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
var timerPath string
|
|
if arg := flag.Arg(0); arg == "" {
|
|
timerPath = defaultTimerPath
|
|
} else {
|
|
timerPath = arg
|
|
}
|
|
timerFile, err := os.Open(timerPath)
|
|
if err != nil {
|
|
fmt.Printf("Can't open %s. Got error: %s", timerPath, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
var timerTable map[string]map[string]int64
|
|
if err := toml.NewDecoder(timerFile).Decode(&timerTable); err != nil {
|
|
fmt.Printf("Can't decode %s. Got error: %s", timerPath, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
users := make(map[string]time.Duration)
|
|
|
|
for _, entries := range timerTable {
|
|
for user, duration := range entries {
|
|
users[user] += time.Duration(int64(time.Second) * duration)
|
|
}
|
|
}
|
|
|
|
for user, duration := range users {
|
|
fmt.Printf("%s: %v\n", user, duration)
|
|
}
|
|
|
|
}
|