mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
fix linter errors
This commit is contained in:
parent
998e8052c5
commit
972b0b276f
3 changed files with 16 additions and 8 deletions
|
@ -1,7 +1,6 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/containrrr/watchtower/actions"
|
||||
"github.com/containrrr/watchtower/container"
|
||||
"github.com/containrrr/watchtower/internal/flags"
|
||||
|
@ -17,6 +16,8 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// DockerAPIMinVersion is the minimum version of the docker api required to
|
||||
// use watchtower
|
||||
const DockerAPIMinVersion string = "1.24"
|
||||
|
||||
var (
|
||||
|
@ -48,13 +49,14 @@ func init() {
|
|||
flags.RegisterNotificationFlags(rootCmd)
|
||||
}
|
||||
|
||||
// Execute the root func and exit in case of errors
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// PreRun is a lifecycle hook that runs before the command is executed.
|
||||
func PreRun(cmd *cobra.Command, args []string) {
|
||||
f := cmd.PersistentFlags()
|
||||
|
||||
|
@ -99,6 +101,7 @@ func PreRun(cmd *cobra.Command, args []string) {
|
|||
notifier = notifications.NewNotifier(cmd)
|
||||
}
|
||||
|
||||
// Run is the main execution flow of the command
|
||||
func Run(c *cobra.Command, names []string) {
|
||||
filter := container.BuildFilter(names, enableLabel)
|
||||
runOnce, _ := c.PersistentFlags().GetBool("run-once")
|
||||
|
|
|
@ -8,12 +8,14 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// RegisterDockerFlags that are used directly by the docker api client
|
||||
func RegisterDockerFlags(rootCmd *cobra.Command) {
|
||||
flags := rootCmd.PersistentFlags()
|
||||
flags.StringP("host", "H", viper.GetString("DOCKER_HOST"), "daemon socket to connect to")
|
||||
flags.BoolP("tlsverify", "v", viper.GetBool("DOCKER_TLS_VERIFY"), "use TLS and verify the remote")
|
||||
}
|
||||
|
||||
// RegisterSystemFlags that are used by watchtower to modify the program flow
|
||||
func RegisterSystemFlags(rootCmd *cobra.Command) {
|
||||
flags := rootCmd.PersistentFlags()
|
||||
flags.IntP(
|
||||
|
@ -82,6 +84,7 @@ func RegisterSystemFlags(rootCmd *cobra.Command) {
|
|||
"Will also include created and exited containers")
|
||||
}
|
||||
|
||||
// RegisterNotificationFlags that are used by watchtower to send notifications
|
||||
func RegisterNotificationFlags(rootCmd *cobra.Command) {
|
||||
flags := rootCmd.PersistentFlags()
|
||||
|
||||
|
@ -185,6 +188,7 @@ Should only be used for testing.
|
|||
"The MSTeams notifier will try to extract log entry fields as MSTeams message facts")
|
||||
}
|
||||
|
||||
// SetDefaults provides default values for environment variables
|
||||
func SetDefaults() {
|
||||
viper.AutomaticEnv()
|
||||
viper.SetDefault("DOCKER_HOST", "unix:///var/run/docker.sock")
|
||||
|
@ -196,7 +200,7 @@ func SetDefaults() {
|
|||
viper.SetDefault("WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER", "watchtower")
|
||||
}
|
||||
|
||||
// envConfig translates the command-line options into environment variables
|
||||
// EnvConfig translates the command-line options into environment variables
|
||||
// that will initialize the api client
|
||||
func EnvConfig(cmd *cobra.Command, dockerAPIMinVersion string) error {
|
||||
var err error
|
||||
|
@ -223,6 +227,7 @@ func EnvConfig(cmd *cobra.Command, dockerAPIMinVersion string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ReadFlags reads common flags used in the main program flow of watchtower
|
||||
func ReadFlags(cmd *cobra.Command) (bool, bool, bool, time.Duration) {
|
||||
flags := cmd.PersistentFlags()
|
||||
|
||||
|
|
|
@ -17,19 +17,19 @@ type slackTypeNotifier struct {
|
|||
func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) typeNotifier {
|
||||
flags := c.PersistentFlags()
|
||||
|
||||
hookUrl, _ := flags.GetString("notification-slack-hook-url")
|
||||
hookURL, _ := flags.GetString("notification-slack-hook-url")
|
||||
userName, _ := flags.GetString("notification-slack-identifier")
|
||||
channel, _ := flags.GetString("notification-slack-channel")
|
||||
emoji, _ := flags.GetString("notification-slack-icon-emoji")
|
||||
iconUrl, _ := flags.GetString("notification-slack-icon-url")
|
||||
iconURL, _ := flags.GetString("notification-slack-icon-url")
|
||||
|
||||
n := &slackTypeNotifier{
|
||||
SlackrusHook: slackrus.SlackrusHook{
|
||||
HookURL: hookUrl,
|
||||
HookURL: hookURL,
|
||||
Username: userName,
|
||||
Channel: channel,
|
||||
IconEmoji: emoji,
|
||||
IconURL: iconUrl,
|
||||
IconURL: iconURL,
|
||||
AcceptedLevels: acceptedLogLevels,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue