mirror of
https://github.com/docker/compose.git
synced 2026-10-12 02:13:08 +00:00
golangci-lint: enable perfsprint linter
Signed-off-by: Sebastiaan van Stijn <[email protected]>
This commit is contained in:
committed by
Guillaume Lours
parent
e9491499f1
commit
063ef45da1
@@ -718,13 +718,13 @@ func selectEventProcessor(dockerCli command.Cli, progress, ansi string, detached
|
||||
}
|
||||
case display.ModeTTY:
|
||||
if ansi == "never" {
|
||||
return nil, fmt.Errorf("can't use --progress tty while ANSI support is disabled")
|
||||
return nil, errors.New("can't use --progress tty while ANSI support is disabled")
|
||||
}
|
||||
display.Mode = display.ModeTTY
|
||||
return display.Full(dockerCli.Err(), stdinfo(dockerCli), detached), nil
|
||||
case display.ModePlain:
|
||||
if ansi == "always" {
|
||||
return nil, fmt.Errorf("can't use --progress plain while ANSI support is forced")
|
||||
return nil, errors.New("can't use --progress plain while ANSI support is forced")
|
||||
}
|
||||
display.Mode = display.ModePlain
|
||||
return display.Plain(dockerCli.Err()), nil
|
||||
|
||||
@@ -18,6 +18,7 @@ package compose
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -63,10 +64,10 @@ func createCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Bac
|
||||
PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
|
||||
opts.pullChanged = cmd.Flags().Changed("pull")
|
||||
if opts.Build && opts.noBuild {
|
||||
return fmt.Errorf("--build and --no-build are incompatible")
|
||||
return errors.New("--build and --no-build are incompatible")
|
||||
}
|
||||
if opts.forceRecreate && opts.noRecreate {
|
||||
return fmt.Errorf("--force-recreate and --no-recreate are incompatible")
|
||||
return errors.New("--force-recreate and --no-recreate are incompatible")
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
|
||||
+2
-2
@@ -19,8 +19,8 @@ package compose
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/compose-spec/compose-go/v2/types"
|
||||
"github.com/docker/cli/cli"
|
||||
@@ -133,7 +133,7 @@ func runExec(ctx context.Context, dockerCli command.Cli, backendOptions *Backend
|
||||
}
|
||||
exitCode, err := backend.Exec(ctx, projectName, execOpts)
|
||||
if exitCode != 0 {
|
||||
errMsg := fmt.Sprintf("exit status %d", exitCode)
|
||||
errMsg := "exit status " + strconv.Itoa(exitCode)
|
||||
if err != nil && err.Error() != "" {
|
||||
errMsg = err.Error()
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package compose
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@@ -58,7 +59,7 @@ func generateCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *B
|
||||
func runGenerate(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts generateOptions, containers []string) error {
|
||||
_, _ = fmt.Fprintln(os.Stderr, "generate command is EXPERIMENTAL")
|
||||
if len(containers) == 0 {
|
||||
return fmt.Errorf("at least one container must be specified")
|
||||
return errors.New("at least one container must be specified")
|
||||
}
|
||||
|
||||
backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
|
||||
|
||||
@@ -18,6 +18,7 @@ package compose
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -169,7 +170,7 @@ func promptForInterpolatedVariables(ctx context.Context, dockerCli command.Cli,
|
||||
}
|
||||
|
||||
if !confirmed {
|
||||
return fmt.Errorf("operation cancelled by user")
|
||||
return errors.New("operation cancelled by user")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -292,7 +293,7 @@ func confirmRemoteIncludes(dockerCli command.Cli, options buildOptions, assumeYe
|
||||
return err
|
||||
}
|
||||
if !confirmed {
|
||||
return fmt.Errorf("operation cancelled by user")
|
||||
return errors.New("operation cancelled by user")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ package compose
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -168,7 +168,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backen
|
||||
options.Command = args[1:]
|
||||
}
|
||||
if len(options.publish) > 0 && options.servicePorts {
|
||||
return fmt.Errorf("--service-ports and --publish are incompatible")
|
||||
return errors.New("--service-ports and --publish are incompatible")
|
||||
}
|
||||
if cmd.Flags().Changed("entrypoint") {
|
||||
command, err := shellwords.Parse(options.entrypoint)
|
||||
@@ -179,7 +179,7 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backen
|
||||
}
|
||||
if cmd.Flags().Changed("tty") {
|
||||
if cmd.Flags().Changed("no-tty") {
|
||||
return fmt.Errorf("--tty and --no-tty can't be used together")
|
||||
return errors.New("--tty and --no-tty can't be used together")
|
||||
} else {
|
||||
options.noTty = !ttyFlag
|
||||
}
|
||||
@@ -303,7 +303,7 @@ func runRun(ctx context.Context, backend api.Compose, project *types.Project, op
|
||||
for _, s := range options.labels {
|
||||
key, val, ok := strings.Cut(s, "=")
|
||||
if !ok {
|
||||
return fmt.Errorf("label must be set as KEY=VALUE")
|
||||
return errors.New("label must be set as KEY=VALUE")
|
||||
}
|
||||
labels[key] = val
|
||||
}
|
||||
|
||||
+11
-11
@@ -138,7 +138,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backend
|
||||
up.resolveNavigationMenu(dockerCli)
|
||||
|
||||
if !p.All && len(project.Services) == 0 {
|
||||
return fmt.Errorf("no service selected")
|
||||
return errors.New("no service selected")
|
||||
}
|
||||
|
||||
return runUp(ctx, dockerCli, backendOptions, create, up, build, project, services)
|
||||
@@ -188,41 +188,41 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Backend
|
||||
|
||||
func validateFlags(up *upOptions, create *createOptions) error {
|
||||
if up.waitTimeout < 0 {
|
||||
return fmt.Errorf("--wait-timeout must be a non-negative integer")
|
||||
return errors.New("--wait-timeout must be a non-negative integer")
|
||||
}
|
||||
if up.exitCodeFrom != "" && !up.cascadeFail {
|
||||
up.cascadeStop = true
|
||||
}
|
||||
if up.cascadeStop && up.cascadeFail {
|
||||
return fmt.Errorf("--abort-on-container-failure cannot be combined with --abort-on-container-exit")
|
||||
return errors.New("--abort-on-container-failure cannot be combined with --abort-on-container-exit")
|
||||
}
|
||||
if up.wait {
|
||||
if up.attachDependencies || up.cascadeStop || len(up.attach) > 0 {
|
||||
return fmt.Errorf("--wait cannot be combined with --abort-on-container-exit, --attach or --attach-dependencies")
|
||||
return errors.New("--wait cannot be combined with --abort-on-container-exit, --attach or --attach-dependencies")
|
||||
}
|
||||
up.Detach = true
|
||||
}
|
||||
if create.Build && create.noBuild {
|
||||
return fmt.Errorf("--build and --no-build are incompatible")
|
||||
return errors.New("--build and --no-build are incompatible")
|
||||
}
|
||||
if up.Detach && (up.attachDependencies || up.cascadeStop || up.cascadeFail || len(up.attach) > 0 || up.watch) {
|
||||
if up.wait {
|
||||
return fmt.Errorf("--wait cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch")
|
||||
return errors.New("--wait cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch")
|
||||
} else {
|
||||
return fmt.Errorf("--detach cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch")
|
||||
return errors.New("--detach cannot be combined with --abort-on-container-exit, --abort-on-container-failure, --attach, --attach-dependencies or --watch")
|
||||
}
|
||||
}
|
||||
if create.noInherit && create.noRecreate {
|
||||
return fmt.Errorf("--no-recreate and --renew-anon-volumes are incompatible")
|
||||
return errors.New("--no-recreate and --renew-anon-volumes are incompatible")
|
||||
}
|
||||
if create.forceRecreate && create.noRecreate {
|
||||
return fmt.Errorf("--force-recreate and --no-recreate are incompatible")
|
||||
return errors.New("--force-recreate and --no-recreate are incompatible")
|
||||
}
|
||||
if create.recreateDeps && create.noRecreate {
|
||||
return fmt.Errorf("--always-recreate-deps and --no-recreate are incompatible")
|
||||
return errors.New("--always-recreate-deps and --no-recreate are incompatible")
|
||||
}
|
||||
if create.noBuild && up.watch {
|
||||
return fmt.Errorf("--no-build and --watch are incompatible")
|
||||
return errors.New("--no-build and --watch are incompatible")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ func (c *ContainerContext) Mounts() string {
|
||||
|
||||
// LocalVolumes returns the number of volumes using the "local" volume driver.
|
||||
func (c *ContainerContext) LocalVolumes() string {
|
||||
return fmt.Sprintf("%d", c.c.LocalVolumes)
|
||||
return strconv.Itoa(c.c.LocalVolumes)
|
||||
}
|
||||
|
||||
// Networks returns a comma-separated string of networks that the container is
|
||||
|
||||
@@ -61,7 +61,7 @@ func (ke *KeyboardError) printError(height int, info string) {
|
||||
func (ke *KeyboardError) addError(prefix string, err error) {
|
||||
ke.timeStart = time.Now()
|
||||
|
||||
prefix = ansiColor(CYAN, fmt.Sprintf("%s →", prefix), BOLD)
|
||||
prefix = ansiColor(CYAN, prefix+" →", BOLD)
|
||||
errorString := fmt.Sprintf("%s %s", prefix, err.Error())
|
||||
|
||||
ke.err = errors.New(errorString)
|
||||
@@ -210,10 +210,10 @@ func (lk *LogKeyboard) openDockerDesktop(ctx context.Context, project *types.Pro
|
||||
go func() {
|
||||
_ = tracing.EventWrapFuncForErrGroup(ctx, "menu/gui", tracing.SpanOptions{},
|
||||
func(ctx context.Context) error {
|
||||
link := fmt.Sprintf("docker-desktop://dashboard/apps/%s", project.Name)
|
||||
link := "docker-desktop://dashboard/apps/" + project.Name
|
||||
err := open.Run(link)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not open Docker Desktop")
|
||||
err = errors.New("could not open Docker Desktop")
|
||||
lk.keyboardError("View", err)
|
||||
}
|
||||
return err
|
||||
@@ -228,10 +228,10 @@ func (lk *LogKeyboard) openDDComposeUI(ctx context.Context, project *types.Proje
|
||||
go func() {
|
||||
_ = tracing.EventWrapFuncForErrGroup(ctx, "menu/gui/composeview", tracing.SpanOptions{},
|
||||
func(ctx context.Context) error {
|
||||
link := fmt.Sprintf("docker-desktop://dashboard/docker-compose/%s", project.Name)
|
||||
link := "docker-desktop://dashboard/docker-compose/" + project.Name
|
||||
err := open.Run(link)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not open Docker Desktop Compose UI")
|
||||
err = errors.New("could not open Docker Desktop Compose UI")
|
||||
lk.keyboardError("View Config", err)
|
||||
}
|
||||
return err
|
||||
@@ -264,7 +264,7 @@ func (lk *LogKeyboard) openDDWatchDocs(ctx context.Context, project *types.Proje
|
||||
link := fmt.Sprintf("docker-desktop://dashboard/docker-compose/%s/watch", project.Name)
|
||||
err := open.Run(link)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not open Docker Desktop Compose UI")
|
||||
err = errors.New("could not open Docker Desktop Compose UI")
|
||||
lk.keyboardError("Watch Docs", err)
|
||||
}
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user