first version
This commit is contained in:
parent
4420e74323
commit
137e6287be
3
.timer.toml
Normal file
3
.timer.toml
Normal file
@ -0,0 +1,3 @@
|
||||
## dates and their corresponding seconds been here :)
|
||||
[24-10-16]
|
||||
u80864958_at_u80864958 = 1698
|
5
go.mod
Normal file
5
go.mod
Normal 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
2
go.sum
Normal 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
47
main.go
Normal 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)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user