refactor(cmd/compose/run): remove redundant len check

From the Go specification [1]:

  "1. For a nil slice, the number of iterations is 0."

`len` returns 0 if the slice is nil [2]. Therefore, checking
`len(v) > 0` before a loop is unnecessary.

[1]: https://go.dev/ref/spec#For_range
[2]: https://pkg.go.dev/builtin#len

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun 2023-10-03 01:36:56 +08:00
parent b8773ad1c5
commit 6c345b3755
No known key found for this signature in database
GPG key ID: DAEBBD2E34C111E6
3 changed files with 23 additions and 11 deletions

View file

@ -80,11 +80,10 @@ func (options runOptions) apply(project *types.Project) error {
target.Tty = !options.noTty
target.StdinOpen = options.interactive
// --service-ports and --publish are incompatible
if !options.servicePorts {
target.Ports = []types.ServicePortConfig{}
}
if len(options.publish) > 0 {
target.Ports = []types.ServicePortConfig{}
for _, p := range options.publish {
config, err := types.ParsePortConfig(p)
if err != nil {
@ -93,14 +92,13 @@ func (options runOptions) apply(project *types.Project) error {
target.Ports = append(target.Ports, config...)
}
}
if len(options.volumes) > 0 {
for _, v := range options.volumes {
volume, err := loader.ParseVolume(v)
if err != nil {
return err
}
target.Volumes = append(target.Volumes, volume)
for _, v := range options.volumes {
volume, err := loader.ParseVolume(v)
if err != nil {
return err
}
target.Volumes = append(target.Volumes, volume)
}
for i, s := range project.Services {