diff options
Diffstat (limited to 'config/triggers.go')
-rw-r--r-- | config/triggers.go | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/config/triggers.go b/config/triggers.go index c0e70d40..82750c2d 100644 --- a/config/triggers.go +++ b/config/triggers.go @@ -9,43 +9,45 @@ import ( ) type TriggersConfig struct { - NewEmail []string `ini:"-"` + NewEmail []string `ini:"new-email" parse:"ParseNewEmail"` } -var Triggers = &TriggersConfig{} +var Triggers = new(TriggersConfig) func parseTriggers(file *ini.File) error { - var cmd string - triggers, err := file.GetSection("triggers") + if err := MapToStruct(file.Section("triggers"), Triggers, true); err != nil { + return err + } + log.Debugf("aerc.conf: [triggers] %#v", Triggers) + return nil +} + +func (t *TriggersConfig) ParseNewEmail(_ *ini.Section, key *ini.Key) ([]string, error) { + cmd := indexFmtRegexp.ReplaceAllStringFunc( + key.String(), + func(s string) string { + runes := []rune(s) + t, _ := indexVerbToTemplate(runes[len(runes)-1]) + return t + }, + ) + args, err := shlex.Split(cmd) if err != nil { - goto out + return nil, err } - if key := triggers.Key("new-email"); key != nil { - cmd = indexFmtRegexp.ReplaceAllStringFunc( - key.String(), - func(s string) string { - runes := []rune(s) - t, _ := indexVerbToTemplate(runes[len(runes)-1]) - return t - }, - ) - Triggers.NewEmail, err = shlex.Split(cmd) - if err != nil { - return err - } - if cmd != key.String() { - log.Warnf("%s %s", - "The new-email trigger now uses templates instead of %-based placeholders.", - "Backward compatibility will be removed in aerc 0.17.") - Warnings = append(Warnings, Warning{ - Title: "FORMAT CHANGED: [triggers].new-email", - Body: ` + if cmd != key.String() { + log.Warnf("%s %s", + "The new-email trigger now uses templates instead of %-based placeholders.", + "Backward compatibility will be removed in aerc 0.17.") + Warnings = append(Warnings, Warning{ + Title: "FORMAT CHANGED: [triggers].new-email", + Body: ` The new-email trigger now uses templates instead of %-based placeholders. Your configuration in this instance was automatically converted to: [triggers] -new-email = ` + format.ShellQuote(Triggers.NewEmail) + ` +new-email = ` + format.ShellQuote(args) + ` Your configuration file was not changed. To make this change permanent and to dismiss this warning on launch, replace the above line into aerc.conf. See @@ -53,10 +55,7 @@ aerc-config(5) for more details. The automatic conversion of new-email will be removed in aerc 0.17. `, - }) - } + }) } -out: - log.Debugf("aerc.conf: [triggers] %#v", Triggers) - return nil + return args, nil } |