Merge pull request #1525 from ulyssessouza/fix-profiles

Fix compose config --profiles
This commit is contained in:
Anca Iordache 2021-04-12 17:00:25 +02:00 committed by GitHub
commit 8b245d99fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View File

@ -77,13 +77,11 @@ func (o *projectOptions) toProject(services []string, po ...cli.ProjectOptionsFn
return nil, err return nil, err
} }
if len(services) != 0 {
s, err := project.GetServices(services...) s, err := project.GetServices(services...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
o.Profiles = append(o.Profiles, s.GetProfiles()...) o.Profiles = append(o.Profiles, s.GetProfiles()...)
}
if profiles, ok := options.Environment["COMPOSE_PROFILES"]; ok { if profiles, ok := options.Environment["COMPOSE_PROFILES"]; ok {
o.Profiles = append(o.Profiles, strings.Split(profiles, ",")...) o.Profiles = append(o.Profiles, strings.Split(profiles, ",")...)

View File

@ -78,7 +78,7 @@ func convertCommand(p *projectOptions) *cobra.Command {
return runHash(opts) return runHash(opts)
} }
if opts.profiles { if opts.profiles {
return runProfiles(opts) return runProfiles(opts, args)
} }
return runConvert(cmd.Context(), opts, args) return runConvert(cmd.Context(), opts, args)
@ -195,19 +195,19 @@ func runHash(opts convertOptions) error {
return nil return nil
} }
func runProfiles(opts convertOptions) error { func runProfiles(opts convertOptions, services []string) error {
profiles := map[string]struct{}{} profiles := map[string]interface{}{}
project, err := opts.toProject(nil) _, err := opts.toProject(services)
if err != nil { if err != nil {
return err return err
} }
for _, s := range project.Services { if opts.projectOptions != nil {
for _, p := range s.Profiles { for _, p := range opts.projectOptions.Profiles {
profiles[p] = struct{}{} profiles[p] = nil
} }
} for p := range profiles {
for _, p := range profiles {
fmt.Println(p) fmt.Println(p)
} }
}
return nil return nil
} }