diff --git a/internal/app/wait4x/cmd/dns/a.go b/internal/app/wait4x/cmd/dns/a.go index 4bfbef9..8f30ad7 100644 --- a/internal/app/wait4x/cmd/dns/a.go +++ b/internal/app/wait4x/cmd/dns/a.go @@ -16,6 +16,7 @@ package dns import ( "errors" + "github.com/go-logr/logr" "github.com/spf13/cobra" "wait4x.dev/v2/checker/dns" "wait4x.dev/v2/waiter" @@ -34,14 +35,14 @@ func NewACommand() *cobra.Command { return nil }, Example: ` -# Check A existence -wait4x dns A wait4x.dev + # Check A existence + wait4x dns A wait4x.dev -# Check A is wait4x.dev -wait4x dns A wait4x.dev 172.67.154.180 + # Check A is wait4x.dev + wait4x dns A wait4x.dev 172.67.154.180 -# Check A by defined nameserver -wait4x dns A wait4x.dev 172.67.154.180 -n gordon.ns.cloudflare.com + # Check A by defined nameserver + wait4x dns A wait4x.dev 172.67.154.180 -n gordon.ns.cloudflare.com `, RunE: runA, } @@ -53,9 +54,13 @@ func runA(cmd *cobra.Command, args []string) error { interval, _ := cmd.Flags().GetDuration("interval") timeout, _ := cmd.Flags().GetDuration("timeout") invertCheck, _ := cmd.Flags().GetBool("invert-check") - nameserver, _ := cmd.Flags().GetString("nameserver") + logger, err := logr.FromContext(cmd.Context()) + if err != nil { + return err + } + address := args[0] var expectedValue string if len(args) == 2 { @@ -67,10 +72,12 @@ func runA(cmd *cobra.Command, args []string) error { dns.WithExpectedValue(expectedValue), dns.WithNameServer(nameserver), ) + return waiter.WaitContext(cmd.Context(), dc, waiter.WithTimeout(timeout), waiter.WithInterval(interval), waiter.WithInvertCheck(invertCheck), + waiter.WithLogger(logger), ) } diff --git a/internal/app/wait4x/cmd/dns/aaaa.go b/internal/app/wait4x/cmd/dns/aaaa.go index 05499d3..72c5844 100644 --- a/internal/app/wait4x/cmd/dns/aaaa.go +++ b/internal/app/wait4x/cmd/dns/aaaa.go @@ -16,6 +16,7 @@ package dns import ( "errors" + "github.com/go-logr/logr" "github.com/spf13/cobra" "wait4x.dev/v2/checker/dns" "wait4x.dev/v2/waiter" @@ -34,14 +35,14 @@ func NewAAAACommand() *cobra.Command { return nil }, Example: ` -# Check AAAA existence -wait4x dns AAAA wait4x.dev + # Check AAAA existence + wait4x dns AAAA wait4x.dev -# Check AAAA is wait4x.dev -wait4x dns AAAA wait4x.dev '2606:4700:3033::ac43:9ab4' + # Check AAAA is wait4x.dev + wait4x dns AAAA wait4x.dev '2606:4700:3033::ac43:9ab4' -# Check AAAA by defined nameserver -wait4x dns AAAA wait4x.dev '2606:4700:3033::ac43:9ab4' -n gordon.ns.cloudflare.com + # Check AAAA by defined nameserver + wait4x dns AAAA wait4x.dev '2606:4700:3033::ac43:9ab4' -n gordon.ns.cloudflare.com `, RunE: runAAAA, } @@ -53,9 +54,13 @@ func runAAAA(cmd *cobra.Command, args []string) error { interval, _ := cmd.Flags().GetDuration("interval") timeout, _ := cmd.Flags().GetDuration("timeout") invertCheck, _ := cmd.Flags().GetBool("invert-check") - nameserver, _ := cmd.Flags().GetString("nameserver") + logger, err := logr.FromContext(cmd.Context()) + if err != nil { + return err + } + address := args[0] var expectedValue string if len(args) == 2 { @@ -67,10 +72,12 @@ func runAAAA(cmd *cobra.Command, args []string) error { dns.WithExpectedValue(expectedValue), dns.WithNameServer(nameserver), ) + return waiter.WaitContext(cmd.Context(), dc, waiter.WithTimeout(timeout), waiter.WithInterval(interval), waiter.WithInvertCheck(invertCheck), + waiter.WithLogger(logger), ) } diff --git a/internal/app/wait4x/cmd/dns/cname.go b/internal/app/wait4x/cmd/dns/cname.go index 6c425dc..ec4873c 100644 --- a/internal/app/wait4x/cmd/dns/cname.go +++ b/internal/app/wait4x/cmd/dns/cname.go @@ -16,6 +16,7 @@ package dns import ( "errors" + "github.com/go-logr/logr" "github.com/spf13/cobra" "wait4x.dev/v2/checker/dns" "wait4x.dev/v2/waiter" @@ -34,14 +35,14 @@ func NewCNAMECommand() *cobra.Command { return nil }, Example: ` -# Check CNAME existence -wait4x dns CNAME 172.67.154.180 + # Check CNAME existence + wait4x dns CNAME 172.67.154.180 -# Check CNAME is wait4x.dev -wait4x dns CNAME 172.67.154.180 wait4x.dev + # Check CNAME is wait4x.dev + wait4x dns CNAME 172.67.154.180 wait4x.dev -# Check CNAME by defined nameserver -wait4x dns CNAME 172.67.154.180 -n gordon.ns.cloudflare.com + # Check CNAME by defined nameserver + wait4x dns CNAME 172.67.154.180 -n gordon.ns.cloudflare.com `, RunE: runCNAME, } @@ -53,9 +54,13 @@ func runCNAME(cmd *cobra.Command, args []string) error { interval, _ := cmd.Flags().GetDuration("interval") timeout, _ := cmd.Flags().GetDuration("timeout") invertCheck, _ := cmd.Flags().GetBool("invert-check") - nameserver, _ := cmd.Flags().GetString("nameserver") + logger, err := logr.FromContext(cmd.Context()) + if err != nil { + return err + } + address := args[0] var expectedValue string if len(args) == 2 { @@ -67,10 +72,12 @@ func runCNAME(cmd *cobra.Command, args []string) error { dns.WithExpectedValue(expectedValue), dns.WithNameServer(nameserver), ) + return waiter.WaitContext(cmd.Context(), dc, waiter.WithTimeout(timeout), waiter.WithInterval(interval), waiter.WithInvertCheck(invertCheck), + waiter.WithLogger(logger), ) } diff --git a/internal/app/wait4x/cmd/dns/dns.go b/internal/app/wait4x/cmd/dns/dns.go index 3f195b2..1a6df8b 100644 --- a/internal/app/wait4x/cmd/dns/dns.go +++ b/internal/app/wait4x/cmd/dns/dns.go @@ -15,41 +15,16 @@ package dns import ( - "errors" - "github.com/spf13/cobra" ) -func NewDNSCommand(parent *cobra.Command) *cobra.Command { +func NewDNSCommand() *cobra.Command { command := &cobra.Command{ - Use: "dns COMMAND [flags] [--command [args...]]", + Use: "dns", Short: "Check DNS records", - Args: func(cmd *cobra.Command, args []string) error { - if len(args) < 1 { - return errors.New("ADDRESS is required argument for the dns command") - } - - return nil - }, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - err := parent.PersistentPreRunE(cmd, args) - if err != nil { - return err - } - - return nil - }, - PersistentPostRunE: func(cmd *cobra.Command, args []string) error { - err := parent.PersistentPostRunE(cmd, args) - if err != nil { - return err - } - - return nil - }, } - command.Flags().String("nameserver", "", " Address of the nameserver to send packets to") + command.PersistentFlags().String("nameserver", "", " Address of the nameserver to send packets to") command.AddCommand(NewACommand()) command.AddCommand(NewAAAACommand()) diff --git a/internal/app/wait4x/cmd/dns/mx.go b/internal/app/wait4x/cmd/dns/mx.go index 10fb75a..ef95337 100644 --- a/internal/app/wait4x/cmd/dns/mx.go +++ b/internal/app/wait4x/cmd/dns/mx.go @@ -16,6 +16,7 @@ package dns import ( "errors" + "github.com/go-logr/logr" "github.com/spf13/cobra" "wait4x.dev/v2/checker/dns" "wait4x.dev/v2/waiter" @@ -34,14 +35,14 @@ func NewMXCommand() *cobra.Command { return nil }, Example: ` -# Check MX existence -wait4x dns MX wait4x.dev + # Check MX existence + wait4x dns MX wait4x.dev -# Check MX is wait4x.dev -wait4x dns MX wait4x.dev 'route1.mx.cloudflare.net' + # Check MX is wait4x.dev + wait4x dns MX wait4x.dev 'route1.mx.cloudflare.net' -# Check MX by defined nameserver -wait4x dns MX wait4x.dev 'route1.mx.cloudflare.net.' -n gordon.ns.cloudflare.com + # Check MX by defined nameserver + wait4x dns MX wait4x.dev 'route1.mx.cloudflare.net.' -n gordon.ns.cloudflare.com `, RunE: runMX, } @@ -53,9 +54,13 @@ func runMX(cmd *cobra.Command, args []string) error { interval, _ := cmd.Flags().GetDuration("interval") timeout, _ := cmd.Flags().GetDuration("timeout") invertCheck, _ := cmd.Flags().GetBool("invert-check") - nameserver, _ := cmd.Flags().GetString("nameserver") + logger, err := logr.FromContext(cmd.Context()) + if err != nil { + return err + } + address := args[0] var expectedValue string if len(args) == 2 { @@ -67,10 +72,12 @@ func runMX(cmd *cobra.Command, args []string) error { dns.WithExpectedValue(expectedValue), dns.WithNameServer(nameserver), ) + return waiter.WaitContext(cmd.Context(), dc, waiter.WithTimeout(timeout), waiter.WithInterval(interval), waiter.WithInvertCheck(invertCheck), + waiter.WithLogger(logger), ) } diff --git a/internal/app/wait4x/cmd/dns/ns.go b/internal/app/wait4x/cmd/dns/ns.go index 5538b6f..4c2aa8e 100644 --- a/internal/app/wait4x/cmd/dns/ns.go +++ b/internal/app/wait4x/cmd/dns/ns.go @@ -16,6 +16,7 @@ package dns import ( "errors" + "github.com/go-logr/logr" "github.com/spf13/cobra" "wait4x.dev/v2/checker/dns" "wait4x.dev/v2/waiter" @@ -34,14 +35,14 @@ func NewNSCommand() *cobra.Command { return nil }, Example: ` -# Check NS existence -wait4x dns NS wait4x.dev + # Check NS existence + wait4x dns NS wait4x.dev -# Check NS is wait4x.dev -wait4x dns NS wait4x.dev 'emma.ns.cloudflare.com' + # Check NS is wait4x.dev + wait4x dns NS wait4x.dev 'emma.ns.cloudflare.com' -# Check NS by defined nameserver -wait4x dns NS wait4x.dev 'emma.ns.cloudflare.com' -n gordon.ns.cloudflare.com + # Check NS by defined nameserver + wait4x dns NS wait4x.dev 'emma.ns.cloudflare.com' -n gordon.ns.cloudflare.com `, RunE: runNS, } @@ -53,9 +54,13 @@ func runNS(cmd *cobra.Command, args []string) error { interval, _ := cmd.Flags().GetDuration("interval") timeout, _ := cmd.Flags().GetDuration("timeout") invertCheck, _ := cmd.Flags().GetBool("invert-check") - nameserver, _ := cmd.Flags().GetString("nameserver") + logger, err := logr.FromContext(cmd.Context()) + if err != nil { + return err + } + address := args[0] var expectedValue string if len(args) == 2 { @@ -67,10 +72,12 @@ func runNS(cmd *cobra.Command, args []string) error { dns.WithExpectedValue(expectedValue), dns.WithNameServer(nameserver), ) + return waiter.WaitContext(cmd.Context(), dc, waiter.WithTimeout(timeout), waiter.WithInterval(interval), waiter.WithInvertCheck(invertCheck), + waiter.WithLogger(logger), ) } diff --git a/internal/app/wait4x/cmd/dns/txt.go b/internal/app/wait4x/cmd/dns/txt.go index 0dd214d..e45e48f 100644 --- a/internal/app/wait4x/cmd/dns/txt.go +++ b/internal/app/wait4x/cmd/dns/txt.go @@ -16,6 +16,7 @@ package dns import ( "errors" + "github.com/go-logr/logr" "github.com/spf13/cobra" "wait4x.dev/v2/checker/dns" "wait4x.dev/v2/waiter" @@ -34,14 +35,14 @@ func NewTXTCommand() *cobra.Command { return nil }, Example: ` -# Check TXT existence -wait4x dns TXT wait4x.dev + # Check TXT existence + wait4x dns TXT wait4x.dev -# Check TXT is wait4x.dev -wait4x dns TXT wait4x.dev 'include:_spf.mx.cloudflare.net' + # Check TXT is wait4x.dev + wait4x dns TXT wait4x.dev 'include:_spf.mx.cloudflare.net' -# Check TXT by defined nameserver -wait4x dns TXT wait4x.dev 'include:_spf.mx.cloudflare.net' -n gordon.ns.cloudflare.com + # Check TXT by defined nameserver + wait4x dns TXT wait4x.dev 'include:_spf.mx.cloudflare.net' -n gordon.ns.cloudflare.com `, RunE: runTXT, } @@ -53,9 +54,13 @@ func runTXT(cmd *cobra.Command, args []string) error { interval, _ := cmd.Flags().GetDuration("interval") timeout, _ := cmd.Flags().GetDuration("timeout") invertCheck, _ := cmd.Flags().GetBool("invert-check") - nameserver, _ := cmd.Flags().GetString("nameserver") + logger, err := logr.FromContext(cmd.Context()) + if err != nil { + return err + } + address := args[0] var expectedValue string if len(args) == 2 { @@ -72,5 +77,6 @@ func runTXT(cmd *cobra.Command, args []string) error { waiter.WithTimeout(timeout), waiter.WithInterval(interval), waiter.WithInvertCheck(invertCheck), + waiter.WithLogger(logger), ) } diff --git a/internal/app/wait4x/cmd/root.go b/internal/app/wait4x/cmd/root.go index 9eef2c6..47b5387 100644 --- a/internal/app/wait4x/cmd/root.go +++ b/internal/app/wait4x/cmd/root.go @@ -114,7 +114,7 @@ func NewRootCommand() *cobra.Command { func Execute() { rootCmd := NewRootCommand() rootCmd.AddCommand(NewTCPCommand()) - rootCmd.AddCommand(dns.NewDNSCommand(rootCmd)) + rootCmd.AddCommand(dns.NewDNSCommand()) rootCmd.AddCommand(NewHTTPCommand()) rootCmd.AddCommand(NewPostgresqlCommand()) rootCmd.AddCommand(NewMysqlCommand())