parent
5429d3a83b
commit
cdfe8e6062
@ -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 |
||||
} |
@ -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) |
||||
|
||||
} |
||||
|
@ -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 |
||||
} |
Loading…
Reference in new issue