Browse Source

introduce config --profiles for parity with docker-compose

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 4 years ago
parent
commit
25d5367480
1 changed files with 22 additions and 0 deletions
  1. 22 0
      cli/cmd/compose/convert.go

+ 22 - 0
cli/cmd/compose/convert.go

@@ -46,6 +46,7 @@ type convertOptions struct {
 	noInterpolate bool
 	services      bool
 	volumes       bool
+	profiles      bool
 	hash          string
 }
 
@@ -76,6 +77,9 @@ func convertCommand(p *projectOptions) *cobra.Command {
 			if opts.hash != "" {
 				return runHash(opts)
 			}
+			if opts.profiles {
+				return runProfiles(opts)
+			}
 
 			return runConvert(cmd.Context(), opts, args)
 		},
@@ -88,6 +92,7 @@ func convertCommand(p *projectOptions) *cobra.Command {
 
 	flags.BoolVar(&opts.services, "services", false, "Print the service names, one per line.")
 	flags.BoolVar(&opts.volumes, "volumes", false, "Print the volume names, one per line.")
+	flags.BoolVar(&opts.profiles, "profiles", false, "Print the profile names, one per line.")
 	flags.StringVar(&opts.hash, "hash", "", "Print the service config hash, one per line.")
 
 	// add flags for hidden backends
@@ -189,3 +194,20 @@ func runHash(opts convertOptions) error {
 	}
 	return nil
 }
+
+func runProfiles(opts convertOptions) error {
+	profiles := map[string]struct{}{}
+	project, err := opts.toProject(nil)
+	if err != nil {
+		return err
+	}
+	for _, s := range project.Services {
+		for _, p := range s.Profiles {
+			profiles[p] = struct{}{}
+		}
+	}
+	for _, p := range profiles {
+		fmt.Println(p)
+	}
+	return nil
+}