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