A => .gitignore +1 -0
@@ 1,1 @@
+amitm<
\ No newline at end of file
A => examples/amitm.toml +10 -0
@@ 1,10 @@
+[[rules]]
+name = "Golang"
+glob = "*.go"
+action = "put"
+
+[[rules.pipeline]]
+exec = "go fmt $file"
+
+[[rules.pipeline]]
+exec = "echo 'Done formatting $file'"<
\ No newline at end of file
A => go.mod +8 -0
@@ 1,8 @@
+module git.sr.ht/~nvkv/amitm
+
+go 1.15
+
+require (
+ 9fans.net/go v0.0.2
+ github.com/pelletier/go-toml v1.8.1
+)
A => go.sum +5 -0
@@ 1,5 @@
+9fans.net/go v0.0.2 h1:RYM6lWITV8oADrwLfdzxmt8ucfW6UtP9v1jg4qAbqts=
+9fans.net/go v0.0.2/go.mod h1:lfPdxjq9v8pVQXUMBCx5EO5oLXWQFlKRQgs1kEkjoIM=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM=
+github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
A => internal/config/v1/config.go +39 -0
@@ 1,39 @@
+package config
+
+import (
+ "github.com/pelletier/go-toml"
+ "io/ioutil"
+)
+
+type PipelineStep struct {
+ Exec string
+}
+
+type Rule struct {
+ Name string
+ Action string
+ Glob string
+ Pipeline []PipelineStep
+}
+
+type Config struct {
+ actionmap map[string][]*Rule
+ Rules []Rule
+}
+
+func ReadConfig(path string) (*Config, error) {
+ data, err := ioutil.ReadFile(path)
+ if err != nil {
+ return nil, err
+ }
+ cfg := &Config{}
+ err = toml.Unmarshal(data, cfg)
+ if err != nil {
+ return nil, err
+ }
+ cfg.actionmap = make(map[string][]*Rule)
+ for _, rule := range cfg.Rules {
+ cfg.actionmap[rule.Action] = append(cfg.actionmap[rule.Action], &rule)
+ }
+ return cfg, nil
+}
A => internal/config/v1/config_test.go +14 -0
@@ 1,14 @@
+package config
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestReadConfig(t *testing.T) {
+ cfg, err := ReadConfig("../../../examples/amitm.toml")
+ fmt.Printf("cfg: %+v\n", cfg.actionmap)
+ if err != nil {
+ t.Errorf("Can't read example.toml file: %s", err)
+ }
+}