Revert "feat(config): swap viper and cobra for config (#684)"

This reverts commit ff8cb884a0.
This commit is contained in:
Simon Aronsson 2020-12-21 23:08:23 +01:00
parent 89119515af
commit 8b81fbd48d
No known key found for this signature in database
GPG key ID: 8DA57A5FD341605B
12 changed files with 255 additions and 229 deletions

View file

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"github.com/containrrr/shoutrrr/pkg/types"
"github.com/spf13/viper"
"strings"
"text/template"
@ -35,8 +34,9 @@ type shoutrrrTypeNotifier struct {
}
func newShoutrrrNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
flags := c.PersistentFlags()
urls := viper.GetStringSlice("notification-url")
urls, _ := flags.GetStringArray("notification-url")
r, err := shoutrrr.CreateSender(urls...)
if err != nil {
log.Fatalf("Failed to initialize Shoutrrr notifications: %s\n", err.Error())
@ -126,11 +126,12 @@ func (e *shoutrrrTypeNotifier) Fire(entry *log.Entry) error {
return nil
}
func getShoutrrrTemplate(_ *cobra.Command) *template.Template {
func getShoutrrrTemplate(c *cobra.Command) *template.Template {
var tpl *template.Template
var err error
tplString := viper.GetString("notification-template")
flags := c.PersistentFlags()
tplString, err := flags.GetString("notification-template")
funcs := template.FuncMap{
"ToUpper": strings.ToUpper,
@ -140,7 +141,7 @@ func getShoutrrrTemplate(_ *cobra.Command) *template.Template {
// If we succeed in getting a non-empty template configuration
// try to parse the template string.
if tplString != "" {
if tplString != "" && err == nil {
tpl, err = template.New("").Funcs(funcs).Parse(tplString)
}