mirror of
https://github.com/docker/compose.git
synced 2026-08-27 03:45:29 +00:00
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:
parent
b8773ad1c5
commit
6c345b3755
3 changed files with 23 additions and 11 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue