Преглед изворни кода

Fix compose config --profiles

Signed-off-by: Ulysses Souza <[email protected]>
Ulysses Souza пре 4 година
родитељ
комит
6dbfc71a0d
2 измењених фајлова са 14 додато и 16 уклоњено
  1. 4 6
      cli/cmd/compose/compose.go
  2. 10 10
      cli/cmd/compose/convert.go

+ 4 - 6
cli/cmd/compose/compose.go

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

+ 10 - 10
cli/cmd/compose/convert.go

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