Skip to content

Commit 66524e7

Browse files
jarqviglours
authored andcommitted
feat: add --networks flag to config command
Signed-off-by: MohammadHasan Akbari <[email protected]>
1 parent c626bef commit 66524e7

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

cmd/compose/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type configOptions struct {
5050
noResolveEnv bool
5151
services bool
5252
volumes bool
53+
networks bool
5354
profiles bool
5455
images bool
5556
hash string
@@ -111,6 +112,9 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
111112
if opts.volumes {
112113
return runVolumes(ctx, dockerCli, opts)
113114
}
115+
if opts.networks {
116+
return runNetworks(ctx, dockerCli, opts)
117+
}
114118
if opts.hash != "" {
115119
return runHash(ctx, dockerCli, opts)
116120
}
@@ -147,6 +151,7 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command {
147151

148152
flags.BoolVar(&opts.services, "services", false, "Print the service names, one per line.")
149153
flags.BoolVar(&opts.volumes, "volumes", false, "Print the volume names, one per line.")
154+
flags.BoolVar(&opts.networks, "networks", false, "Print the network names, one per line.")
150155
flags.BoolVar(&opts.profiles, "profiles", false, "Print the profile names, one per line.")
151156
flags.BoolVar(&opts.images, "images", false, "Print the image names, one per line.")
152157
flags.StringVar(&opts.hash, "hash", "", "Print the service config hash, one per line.")
@@ -367,6 +372,17 @@ func runVolumes(ctx context.Context, dockerCli command.Cli, opts configOptions)
367372
return nil
368373
}
369374

375+
func runNetworks(ctx context.Context, dockerCli command.Cli, opts configOptions) error {
376+
project, err := opts.ToProject(ctx, dockerCli, nil, cli.WithoutEnvironmentResolution)
377+
if err != nil {
378+
return err
379+
}
380+
for n := range project.Networks {
381+
_, _ = fmt.Fprintln(dockerCli.Out(), n)
382+
}
383+
return nil
384+
}
385+
370386
func runHash(ctx context.Context, dockerCli command.Cli, opts configOptions) error {
371387
var services []string
372388
if opts.hash != "*" {

docs/reference/compose_config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ the canonical format.
1515
| `--hash` | `string` | | Print the service config hash, one per line. |
1616
| `--images` | `bool` | | Print the image names, one per line. |
1717
| `--lock-image-digests` | `bool` | | Produces an override file with image digests |
18+
| `--networks` | `bool` | | Print the network names, one per line. |
1819
| `--no-consistency` | `bool` | | Don't check model consistency - warning: may produce invalid Compose output |
1920
| `--no-env-resolution` | `bool` | | Don't resolve service env files |
2021
| `--no-interpolate` | `bool` | | Don't interpolate environment variables |

docs/reference/docker_compose_config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ options:
5656
experimentalcli: false
5757
kubernetes: false
5858
swarm: false
59+
- option: networks
60+
value_type: bool
61+
default_value: "false"
62+
description: Print the network names, one per line.
63+
deprecated: false
64+
hidden: false
65+
experimental: false
66+
experimentalcli: false
67+
kubernetes: false
68+
swarm: false
5969
- option: no-consistency
6070
value_type: bool
6171
default_value: "false"

0 commit comments

Comments
 (0)