Skip to content

Commit

Permalink
feat(config): enable passing arguments to the rule
Browse files Browse the repository at this point in the history
This build on #188 and allow to specify arguments in the rules.

E.g.

```yaml
rules:
  - name: test
    action: debug
    args: ["a", "b"]
```

cc #187
  • Loading branch information
nobe4 committed Oct 2, 2024
1 parent 82482fa commit 759a702
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/config/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Rule struct {
// Action is the action to take on the filtered notifications.
// See github.com/nobe4/internal/actions for list of available actions.
Action string `mapstructure:"action"`

// Args is the arguments to pass to the Action.
Args []string `mapstructure:"args"`
}

// Test tests the rule for correctness.
Expand Down
2 changes: 1 addition & 1 deletion internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (m *Manager) Apply() error {
continue
}

if err := runner.Run(notification, nil, os.Stdout); err != nil {
if err := runner.Run(notification, rule.Args, os.Stdout); err != nil {
slog.Error("action failed", "action", rule.Action, "err", err)
}
fmt.Fprintln(os.Stdout, "")
Expand Down

0 comments on commit 759a702

Please sign in to comment.