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