introduce config --profiles for parity with docker-compose

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-03-30 10:39:17 +02:00
parent ee4e85ae1d
commit 25d5367480
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
1 changed files with 22 additions and 0 deletions

View File

@ -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
}