Add tags
parent
5ffb4b6b53
commit
33370b4b2d
20
main.go
20
main.go
|
@ -32,21 +32,30 @@ import (
|
|||
type Record struct {
|
||||
Start time.Time
|
||||
End time.Time
|
||||
Tags []string
|
||||
}
|
||||
|
||||
type Records struct {
|
||||
Entries []Record
|
||||
}
|
||||
|
||||
func start() Record {
|
||||
func start(tags []string) Record {
|
||||
fmt.Print(time.Now().Format("2 Jan 2006 15:04:05"))
|
||||
fmt.Println(" Start record")
|
||||
return Record{Start: time.Now()}
|
||||
var record Record
|
||||
record.Start = time.Now()
|
||||
for _, tag := range tags {
|
||||
record.Tags = append(record.Tags, tag)
|
||||
}
|
||||
return record
|
||||
}
|
||||
|
||||
func stop(entry *Record) {
|
||||
func stop(entry *Record, tags []string) {
|
||||
fmt.Print(time.Now().Format("2 Jan 2006 15:04:05"))
|
||||
fmt.Println(" Stop record")
|
||||
for _, tag := range tags {
|
||||
entry.Tags = append(entry.Tags, tag)
|
||||
}
|
||||
entry.End = time.Now()
|
||||
}
|
||||
|
||||
|
@ -68,7 +77,6 @@ func main() {
|
|||
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
|
||||
// var records Records
|
||||
var current *Record
|
||||
json.Unmarshal(byteValue, &data)
|
||||
|
||||
|
@ -84,12 +92,12 @@ func main() {
|
|||
switch args[0] {
|
||||
case "start":
|
||||
if current == nil {
|
||||
data.Entries = append(data.Entries, start())
|
||||
data.Entries = append(data.Entries, start(args[1:]))
|
||||
} else {
|
||||
fmt.Println("There is already a time tracking running")
|
||||
}
|
||||
case "stop":
|
||||
stop(current)
|
||||
stop(current, args[1:])
|
||||
default:
|
||||
fmt.Println("Unknown argument")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue