From d633c33a19eecbd6c4a63bf8187b147f556302df Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 7 Jun 2024 14:42:19 +0200 Subject: [PATCH] config --environment Signed-off-by: Nicolas De Loof --- cmd/compose/config.go | 17 +++++++++++++++++ docs/reference/compose_config.md | 1 + docs/reference/docker_compose_config.yaml | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/cmd/compose/config.go b/cmd/compose/config.go index 9993ca311..8325946cd 100644 --- a/cmd/compose/config.go +++ b/cmd/compose/config.go @@ -54,6 +54,7 @@ type configOptions struct { hash string noConsistency bool variables bool + environment bool } func (o *configOptions) ToProject(ctx context.Context, dockerCli command.Cli, services []string, po ...cli.ProjectOptionsFn) (*types.Project, error) { @@ -118,6 +119,9 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command { if opts.variables { return runVariables(ctx, dockerCli, opts, args) } + if opts.environment { + return runEnvironment(ctx, dockerCli, opts, args) + } return runConfig(ctx, dockerCli, opts, args) }), @@ -138,6 +142,7 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command { flags.BoolVar(&opts.images, "images", false, "Print the image names, one per line.") flags.StringVar(&opts.hash, "hash", "", "Print the service config hash, one per line.") flags.BoolVar(&opts.variables, "variables", false, "Print model variables and default values.") + flags.BoolVar(&opts.environment, "environment", false, "Print environment used for interpolation.") flags.StringVarP(&opts.Output, "output", "o", "", "Save to file (default to stdout)") return cmd @@ -385,6 +390,18 @@ func runVariables(ctx context.Context, dockerCli command.Cli, opts configOptions }, "NAME", "REQUIRED", "DEFAULT VALUE", "ALTERNATE VALUE") } +func runEnvironment(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) error { + project, err := opts.ToProject(ctx, dockerCli, services) + if err != nil { + return err + } + + for _, v := range project.Environment.Values() { + fmt.Println(v) + } + return nil +} + func escapeDollarSign(marshal []byte) []byte { dollar := []byte{'$'} escDollar := []byte{'$', '$'} diff --git a/docs/reference/compose_config.md b/docs/reference/compose_config.md index e38eb5c65..8b9671236 100644 --- a/docs/reference/compose_config.md +++ b/docs/reference/compose_config.md @@ -12,6 +12,7 @@ Parse, resolve and render compose file in canonical format | Name | Type | Default | Description | |:--------------------------|:---------|:--------|:----------------------------------------------------------------------------| | `--dry-run` | | | Execute command in dry run mode | +| `--environment` | | | Print environment used for interpolation. | | `--format` | `string` | `yaml` | Format the output. Values: [yaml \| json] | | `--hash` | `string` | | Print the service config hash, one per line. | | `--images` | | | Print the image names, one per line. | diff --git a/docs/reference/docker_compose_config.yaml b/docs/reference/docker_compose_config.yaml index 68a7b8994..8073d85ab 100644 --- a/docs/reference/docker_compose_config.yaml +++ b/docs/reference/docker_compose_config.yaml @@ -9,6 +9,16 @@ usage: docker compose config [OPTIONS] [SERVICE...] pname: docker compose plink: docker_compose.yaml options: + - option: environment + value_type: bool + default_value: "false" + description: Print environment used for interpolation. + deprecated: false + hidden: false + experimental: false + experimentalcli: false + kubernetes: false + swarm: false - option: format value_type: string default_value: yaml