test
This commit is contained in:
parent
cdfe8e6062
commit
f85131b80a
@ -13,7 +13,7 @@ type Config struct {
|
|||||||
Tasks []Task
|
Tasks []Task
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConfig will take in the filename, load the JSON and return a pointer to Config
|
// LoadConfig will take in the filename, load the JSON and return a pointer to Config, a slice of Tasks
|
||||||
func LoadConfig(filename string) (*Config, error) {
|
func LoadConfig(filename string) (*Config, error) {
|
||||||
file, err := os.ReadFile(filename)
|
file, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
5
main.go
5
main.go
@ -11,12 +11,13 @@ func main() {
|
|||||||
flag.StringVar(&configFlag, "c", "", "path to tasks.json")
|
flag.StringVar(&configFlag, "c", "", "path to tasks.json")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
fmt.Println("Hello World")
|
|
||||||
fmt.Printf("Reading JSON file: %s\n", configFlag)
|
fmt.Printf("Reading JSON file: %s\n", configFlag)
|
||||||
config, err := LoadConfig(configFlag)
|
config, err := LoadConfig(configFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Cannot load config file: %s\n\t%s\n", configFlag, err)
|
fmt.Fprintf(os.Stderr, "Cannot load config file: %s\n\t%s\n", configFlag, err)
|
||||||
}
|
}
|
||||||
fmt.Println(config)
|
//fmt.Println(config.Tasks[0].TaskName)
|
||||||
|
|
||||||
|
TaskRun(*config)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
11
run.go
Normal file
11
run.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// Run will take the config file and for each task, run a go routine
|
||||||
|
func TaskRun(c Config) {
|
||||||
|
for i, v := range c.Tasks {
|
||||||
|
fmt.Printf("%d, %s", i, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
23
tasks.go
23
tasks.go
@ -2,19 +2,14 @@ package main
|
|||||||
|
|
||||||
// TODO: Finish off doc. here
|
// 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 {
|
type Task struct {
|
||||||
TaskName string
|
TaskName string `json:"taskname"`
|
||||||
TaskDesc string
|
TaskDesc string `json:"taskdesc"`
|
||||||
Interval int32
|
Interval int32 `json:"interval"`
|
||||||
CMD string
|
CMD string `json:"cmd"`
|
||||||
Icon string
|
Icon string `json:"icon"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Task) PrintTask() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
20
tasks.json
20
tasks.json
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"Tasks":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"taskname": "Example Task",
|
||||||
|
"taskdesc": "This is placeholder",
|
||||||
|
"interval": -1,
|
||||||
|
"cmd": " ",
|
||||||
|
"icon": " "
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"taskname": "Second Example",
|
||||||
|
"taskdesc": "Still Place holder",
|
||||||
|
"interval": -1,
|
||||||
|
"cmd": " ",
|
||||||
|
"icon": " "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user