Skip to content

Commit 69a8120

Browse files
committed
only warn once about obsolete version
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 10ffb27 commit 69a8120

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

loader/loader.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"github.com/compose-spec/compose-go/v2/validation"
4242
"github.com/mitchellh/mapstructure"
4343
"github.com/sirupsen/logrus"
44+
"golang.org/x/exp/slices"
4445
"gopkg.in/yaml.v3"
4546
)
4647

@@ -84,6 +85,15 @@ type Options struct {
8485
Listeners []Listener
8586
}
8687

88+
var versionWarning []string
89+
90+
func (o *Options) warnObsoleteVersion(file string) {
91+
if !slices.Contains(versionWarning, file) {
92+
logrus.Warning(fmt.Sprintf("%s: `version` is obsolete", file))
93+
}
94+
versionWarning = append(versionWarning, file)
95+
}
96+
8797
type Listener = func(event string, metadata map[string]any)
8898

8999
// Invoke all listeners for an event
@@ -409,6 +419,10 @@ func loadYamlModel(ctx context.Context, config types.ConfigDetails, opts *Option
409419
if err := schema.Validate(dict); err != nil {
410420
return fmt.Errorf("validating %s: %w", file.Filename, err)
411421
}
422+
if _, ok := dict["version"]; ok {
423+
opts.warnObsoleteVersion(file.Filename)
424+
delete(dict, "version")
425+
}
412426
}
413427

414428
return err
@@ -438,11 +452,6 @@ func loadYamlModel(ctx context.Context, config types.ConfigDetails, opts *Option
438452
}
439453
}
440454

441-
if _, ok := dict["version"]; ok {
442-
logrus.Warning("`version` is obsolete")
443-
delete(dict, "version")
444-
}
445-
446455
dict, err = transform.Canonical(dict)
447456
if err != nil {
448457
return nil, err

0 commit comments

Comments
 (0)