changes for tonight, cont tomorrow
This commit is contained in:
parent
5429d3a83b
commit
cdfe8e6062
@ -21,7 +21,7 @@ The JSON structure should look like this:
|
|||||||
```
|
```
|
||||||
|
|
||||||
This file can be placed in either:
|
This file can be placed in either:
|
||||||
* */home/user/.config/rem/tasks.json*
|
* /home/user/.config/rem/tasks.json
|
||||||
* */home/user/go/src/rem/tasks.json*
|
* /home/user/go/src/rem/tasks.json
|
||||||
|
|
||||||
|
|
||||||
|
29
config.go
Normal file
29
config.go
Normal file
@ -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
|
||||||
|
}
|
17
main.go
17
main.go
@ -1,7 +1,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var configFlag string
|
||||||
|
flag.StringVar(&configFlag, "c", "", "path to tasks.json")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
fmt.Println("Hello World")
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
20
tasks.go
Normal file
20
tasks.go
Normal file
@ -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
|
||||||
|
}
|
0
tasks.json
Normal file
0
tasks.json
Normal file
Loading…
x
Reference in New Issue
Block a user