first version

This commit is contained in:
u80864958 2024-10-16 21:31:42 +02:00
parent 4420e74323
commit 137e6287be
4 changed files with 57 additions and 0 deletions

3
.timer.toml Normal file
View File

@ -0,0 +1,3 @@
## dates and their corresponding seconds been here :)
[24-10-16]
u80864958_at_u80864958 = 1698

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module git.schreifuchs.ch/schreifuchs/timer-cli
go 1.22.5
require github.com/pelletier/go-toml/v2 v2.2.3 // indirect

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=

47
main.go Normal file
View File

@ -0,0 +1,47 @@
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)
}
}