1
0
Fork 0

Adding upstream version 0.8.9.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-22 10:16:14 +02:00
parent 3b2c48b5e4
commit c0c4addb85
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
285 changed files with 25880 additions and 0 deletions

37
internal/util/cobra.go Normal file
View file

@ -0,0 +1,37 @@
package util
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// LoadFlagsFromAltSources is a WORKAROUND to make cobra count env vars and
// positional arguments when checking required flags.
func LoadFlagsFromAltSources(cmd *cobra.Command, args []string) {
flags := cmd.Flags()
if len(args) > 0 {
_ = flags.Set("url", args[0])
if len(args) > 1 {
_ = flags.Set("message", args[1])
}
return
}
if hasURLInEnvButNotFlag(cmd) {
_ = flags.Set("url", viper.GetViper().GetString("SHOUTRRR_URL"))
// If the URL has been set in ENV, default the message to read from stdin.
if msg, _ := flags.GetString("message"); msg == "" {
_ = flags.Set("message", "-")
}
}
}
func hasURLInEnvButNotFlag(cmd *cobra.Command) bool {
s, _ := cmd.Flags().GetString("url")
return s == "" && viper.GetViper().GetString("SHOUTRRR_URL") != ""
}