Skip to content

Commit fbf845c

Browse files
committed
add dry-run flag
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 5a2b7b8 commit fbf845c

File tree

6 files changed

+28
-0
lines changed

6 files changed

+28
-0
lines changed

cmd/compose/compose.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func RootCommand(streams api.Streams, backend api.Service) *cobra.Command { //no
261261
verbose bool
262262
version bool
263263
parallel int
264+
dryRun bool
264265
)
265266
c := &cobra.Command{
266267
Short: "Docker Compose",
@@ -335,6 +336,7 @@ func RootCommand(streams api.Streams, backend api.Service) *cobra.Command { //no
335336
if parallel > 0 {
336337
backend.MaxConcurrency(parallel)
337338
}
339+
backend.DryRunMode(dryRun)
338340
return nil
339341
},
340342
}
@@ -389,6 +391,8 @@ func RootCommand(streams api.Streams, backend api.Service) *cobra.Command { //no
389391
c.Flags().MarkHidden("no-ansi") //nolint:errcheck
390392
c.Flags().BoolVar(&verbose, "verbose", false, "Show more output")
391393
c.Flags().MarkHidden("verbose") //nolint:errcheck
394+
c.Flags().BoolVar(&dryRun, "dry-run", false, "Execute command in dry run mode")
395+
c.Flags().MarkHidden("dry-run") //nolint:errcheck
392396
return c
393397
}
394398

docs/reference/compose.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Docker Compose
4141
|:-----------------------|:--------------|:--------|:----------------------------------------------------------------------------------------------------|
4242
| `--ansi` | `string` | `auto` | Control when to print ANSI control characters ("never"\|"always"\|"auto") |
4343
| `--compatibility` | | | Run compose in backward compatibility mode |
44+
| `--dry-run` | | | Execute command in dry run mode |
4445
| `--env-file` | `string` | | Specify an alternate environment file. |
4546
| `-f`, `--file` | `stringArray` | | Compose configuration files |
4647
| `--parallel` | `int` | `-1` | Control max parallelism, -1 for unlimited |

docs/reference/docker_compose.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ options:
178178
experimentalcli: false
179179
kubernetes: false
180180
swarm: false
181+
- option: dry-run
182+
value_type: bool
183+
default_value: "false"
184+
description: Execute command in dry run mode
185+
deprecated: false
186+
hidden: false
187+
experimental: false
188+
experimentalcli: false
189+
kubernetes: false
190+
swarm: false
181191
- option: env-file
182192
value_type: string
183193
description: Specify an alternate environment file.

pkg/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ type Service interface {
7777
Images(ctx context.Context, projectName string, options ImagesOptions) ([]ImageSummary, error)
7878
// MaxConcurrency defines upper limit for concurrent operations against engine API
7979
MaxConcurrency(parallel int)
80+
// DryRunMode defines if dry run applies to the command
81+
DryRunMode(dryRun bool)
8082
// Watch services' development context and sync/notify/rebuild/restart on changes
8183
Watch(ctx context.Context, project *types.Project, services []string, options WatchOptions) error
8284
}

pkg/api/proxy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type ServiceProxy struct {
5252
ImagesFn func(ctx context.Context, projectName string, options ImagesOptions) ([]ImageSummary, error)
5353
WatchFn func(ctx context.Context, project *types.Project, services []string, options WatchOptions) error
5454
MaxConcurrencyFn func(parallel int)
55+
DryRunModeFn func(dryRun bool)
5556
interceptors []Interceptor
5657
}
5758

@@ -324,3 +325,7 @@ func (s *ServiceProxy) Watch(ctx context.Context, project *types.Project, servic
324325
func (s *ServiceProxy) MaxConcurrency(i int) {
325326
s.MaxConcurrencyFn(i)
326327
}
328+
329+
func (s *ServiceProxy) DryRunMode(dryRun bool) {
330+
s.DryRunModeFn(dryRun)
331+
}

pkg/compose/compose.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ func NewComposeService(dockerCli command.Cli) api.Service {
4343
return &composeService{
4444
dockerCli: dockerCli,
4545
maxConcurrency: -1,
46+
dryRun: false,
4647
}
4748
}
4849

4950
type composeService struct {
5051
dockerCli command.Cli
5152
maxConcurrency int
53+
dryRun bool
5254
}
5355

5456
func (s *composeService) apiClient() client.APIClient {
@@ -63,6 +65,10 @@ func (s *composeService) MaxConcurrency(i int) {
6365
s.maxConcurrency = i
6466
}
6567

68+
func (s *composeService) DryRunMode(dryRun bool) {
69+
s.dryRun = dryRun
70+
}
71+
6672
func (s *composeService) stdout() *streams.Out {
6773
return s.dockerCli.Out()
6874
}

0 commit comments

Comments
 (0)