diff --git a/README.md b/README.md index 1c40be7..5fb1860 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The JSON structure should look like this: ``` This file can be placed in either: -* */home/user/.config/rem/tasks.json* -* */home/user/go/src/rem/tasks.json* +* /home/user/.config/rem/tasks.json +* /home/user/go/src/rem/tasks.json diff --git a/config.go b/config.go new file mode 100644 index 0000000..341c7bc --- /dev/null +++ b/config.go @@ -0,0 +1,29 @@ +package main + +import ( + "encoding/json" + "os" +) + +//TODO: Create: +// * LoadConfig +// * CreateSampleConfig + +type Config struct { + Tasks []Task +} + +// LoadConfig will take in the filename, load the JSON and return a pointer to Config +func LoadConfig(filename string) (*Config, error) { + file, err := os.ReadFile(filename) + if err != nil { + return nil, err //nil is used here as we return a pointer to Config + } + + config := &Config{} + err = json.Unmarshal(file, &config) + if err != nil { + return nil, err + } + return config, nil +} diff --git a/main.go b/main.go index 91e7378..d5811d3 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,22 @@ package main -import "fmt" +import ( + "flag" + "fmt" + "os" +) func main() { + var configFlag string + flag.StringVar(&configFlag, "c", "", "path to tasks.json") + flag.Parse() + fmt.Println("Hello World") + fmt.Printf("Reading JSON file: %s\n", configFlag) + config, err := LoadConfig(configFlag) + if err != nil { + fmt.Fprintf(os.Stderr, "Cannot load config file: %s\n\t%s\n", configFlag, err) + } + fmt.Println(config) + } diff --git a/tasks.go b/tasks.go new file mode 100644 index 0000000..9aa3258 --- /dev/null +++ b/tasks.go @@ -0,0 +1,20 @@ +package main + +// TODO: Finish off doc. here + +/* +Task: + + Each 'task' will have a name, desc. time between reminder and a cmd + The 'CMD' will take shell script such as e.g. + $ checkupdates | wc -l + and store the output as a string to use in the desc. + If the 'CMD' is empty, we will just put a new line (maybe change this) +*/ +type Task struct { + TaskName string + TaskDesc string + Interval int32 + CMD string + Icon string +} diff --git a/tasks.json b/tasks.json new file mode 100644 index 0000000..e69de29