aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.go25
-rw-r--r--timetask/time_entry.go46
2 files changed, 70 insertions, 1 deletions
diff --git a/main.go b/main.go
index 3cc1a9e..5c6e5e4 100644
--- a/main.go
+++ b/main.go
@@ -1,10 +1,14 @@
package main
import (
+ "fmt"
"io/ioutil"
"log"
+ "os"
- "gopkg.in/yaml.v1"
+ "com.teddywing/timetasker/timetask"
+
+ "gopkg.in/yaml.v2"
)
type Config struct {
@@ -41,6 +45,25 @@ var config Config
func main() {
loadConfig()
+
+ if len(os.Args) == 1 {
+ fmt.Println("Not enough arguments")
+ os.Exit(1)
+ }
+
+ file_path := os.Args[len(os.Args)-1]
+ file, err := ioutil.ReadFile(file_path)
+ if err != nil {
+ log.Println(err)
+ }
+
+ time_entries := []timetask.TimeEntry{}
+ err = yaml.Unmarshal(file, &time_entries)
+ if err != nil {
+ log.Println(err)
+ }
+
+ log.Printf("%+v", time_entries)
}
func loadConfig() {
diff --git a/timetask/time_entry.go b/timetask/time_entry.go
new file mode 100644
index 0000000..6dfb787
--- /dev/null
+++ b/timetask/time_entry.go
@@ -0,0 +1,46 @@
+package timetask
+
+import "time"
+
+type TimeEntry struct {
+ Client string
+ Project string
+ Task string
+ WorkType string `yaml:"work_type"`
+ Date time.Time
+ Billable bool
+ Description string
+}
+
+// Parse date string into a real date
+func (te *TimeEntry) UnmarshalYAML(unmarshal func(interface{}) error) error {
+ var auxiliary struct {
+ Client string
+ Project string
+ Task string
+ WorkType string `yaml:"work_type"`
+ Date string
+ Billable bool
+ Description string
+ }
+
+ err := unmarshal(&auxiliary)
+ if err != nil {
+ return err
+ }
+
+ date, err := time.Parse("2006-01-02", auxiliary.Date)
+ if err != nil {
+ return err
+ }
+
+ te.Client = auxiliary.Client
+ te.Project = auxiliary.Project
+ te.Task = auxiliary.Task
+ te.WorkType = auxiliary.WorkType
+ te.Date = date
+ te.Billable = auxiliary.Billable
+ te.Description = auxiliary.Description
+
+ return nil
+}