@@ -2,6 +2,7 @@ package main
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "io"
78 "os"
@@ -21,7 +22,6 @@ import (
2122 platformsignals "github.com/docker/cli/cmd/docker/internal/signals"
2223 "github.com/docker/docker/api/types/versions"
2324 "github.com/docker/docker/errdefs"
24- "github.com/pkg/errors"
2525 "github.com/sirupsen/logrus"
2626 "github.com/spf13/cobra"
2727 "github.com/spf13/pflag"
@@ -203,7 +203,7 @@ func setupHelpCommand(dockerCli command.Cli, rootCmd, helpCmd *cobra.Command) {
203203 return helpcmd .Run ()
204204 }
205205 if ! pluginmanager .IsNotFound (err ) {
206- return errors .Errorf ("unknown help topic: %v" , strings .Join (args , " " ))
206+ return fmt .Errorf ("unknown help topic: %v" , strings .Join (args , " " ))
207207 }
208208 }
209209 if origRunE != nil {
@@ -593,7 +593,7 @@ func isSupported(cmd *cobra.Command, details versionDetails) error {
593593}
594594
595595func areFlagsSupported (cmd * cobra.Command , details versionDetails ) error {
596- errs := [] string {}
596+ var errs [] error
597597
598598 cmd .Flags ().VisitAll (func (f * pflag.Flag ) {
599599 if ! f .Changed || len (f .Annotations ) == 0 {
@@ -608,26 +608,23 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
608608 // See commit b39739123b845f872549e91be184cc583f5b387c for details.
609609
610610 if _ , ok := f .Annotations ["version" ]; ok && ! isVersionSupported (f , details .CurrentVersion ()) {
611- errs = append (errs , fmt .Sprintf (`"--%s" requires API version %s, but the Docker daemon API version is %s` , f .Name , getFlagAnnotation (f , "version" ), details .CurrentVersion ()))
611+ errs = append (errs , fmt .Errorf (`"--%s" requires API version %s, but the Docker daemon API version is %s` , f .Name , getFlagAnnotation (f , "version" ), details .CurrentVersion ()))
612612 return
613613 }
614614 if _ , ok := f .Annotations ["ostype" ]; ok && ! isOSTypeSupported (f , details .ServerInfo ().OSType ) {
615- errs = append (errs , fmt .Sprintf (
615+ errs = append (errs , fmt .Errorf (
616616 `"--%s" is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s` ,
617617 f .Name ,
618618 getFlagAnnotation (f , "ostype" ), details .ServerInfo ().OSType ),
619619 )
620620 return
621621 }
622622 if _ , ok := f .Annotations ["experimental" ]; ok && ! details .ServerInfo ().HasExperimental {
623- errs = append (errs , fmt .Sprintf (`"--%s" is only supported on a Docker daemon with experimental features enabled` , f .Name ))
623+ errs = append (errs , fmt .Errorf (`"--%s" is only supported on a Docker daemon with experimental features enabled` , f .Name ))
624624 }
625625 // buildkit-specific flags are noop when buildkit is not enabled, so we do not add an error in that case
626626 })
627- if len (errs ) > 0 {
628- return errors .New (strings .Join (errs , "\n " ))
629- }
630- return nil
627+ return errors .Join (errs ... )
631628}
632629
633630// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
0 commit comments