Skip to content

Commit

Permalink
name set in yaml is equivalent to --project-name
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Dec 19, 2024
1 parent e3dffbf commit b042ad5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"

"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"

"github.com/compose-spec/compose-go/v2/consts"
"github.com/compose-spec/compose-go/v2/dotenv"
Expand Down Expand Up @@ -482,6 +483,20 @@ func (o *ProjectOptions) prepare(ctx context.Context) (*types.ConfigDetails, err
return configDetails, err
}

if o.Name == "" {
type named struct {
Name string `yaml:"name,omitempty"`
}
// if any of the compose file is named, this is equivalent to user passing --project-name
for _, cfg := range configDetails.ConfigFiles {
var n named
yaml.Unmarshal(cfg.Content, &n)
if n.Name != "" {
o.Name = n.Name
}
}
}

o.loadOptions = append(o.loadOptions,
withNamePrecedenceLoad(defaultDir, o),
withConvertWindowsPaths(o),
Expand Down

0 comments on commit b042ad5

Please sign in to comment.