From 137e6287beec2c6dd02586e4064a2ba3781b320a Mon Sep 17 00:00:00 2001 From: u80864958 Date: Wed, 16 Oct 2024 21:31:42 +0200 Subject: [PATCH] first version --- .timer.toml | 3 +++ go.mod | 5 +++++ go.sum | 2 ++ main.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 .timer.toml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.timer.toml b/.timer.toml new file mode 100644 index 0000000..5a1ad43 --- /dev/null +++ b/.timer.toml @@ -0,0 +1,3 @@ +## dates and their corresponding seconds been here :) +[24-10-16] +u80864958_at_u80864958 = 1698 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..45a0706 --- /dev/null +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b61c368 --- /dev/null +++ b/go.sum @@ -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= diff --git a/main.go b/main.go new file mode 100644 index 0000000..ee7140f --- /dev/null +++ b/main.go @@ -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) + } + +}