Skip to content

Commit

Permalink
config --environment
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Jun 11, 2024
1 parent cc09f39 commit d633c33
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}),
Expand All @@ -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
Expand Down Expand Up @@ -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{'$', '$'}
Expand Down
1 change: 1 addition & 0 deletions docs/reference/compose_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/docker_compose_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d633c33

Please sign in to comment.