فهرست منبع

add dry-run flag

Signed-off-by: Guillaume Lours <[email protected]>
Guillaume Lours 2 سال پیش
والد
کامیت
fbf845c5f8
6فایلهای تغییر یافته به همراه28 افزوده شده و 0 حذف شده
  1. 4 0
      cmd/compose/compose.go
  2. 1 0
      docs/reference/compose.md
  3. 10 0
      docs/reference/docker_compose.yaml
  4. 2 0
      pkg/api/api.go
  5. 5 0
      pkg/api/proxy.go
  6. 6 0
      pkg/compose/compose.go

+ 4 - 0
cmd/compose/compose.go

@@ -261,6 +261,7 @@ func RootCommand(streams api.Streams, backend api.Service) *cobra.Command { //no
 		verbose  bool
 		version  bool
 		parallel int
+		dryRun   bool
 	)
 	c := &cobra.Command{
 		Short:            "Docker Compose",
@@ -335,6 +336,7 @@ func RootCommand(streams api.Streams, backend api.Service) *cobra.Command { //no
 			if parallel > 0 {
 				backend.MaxConcurrency(parallel)
 			}
+			backend.DryRunMode(dryRun)
 			return nil
 		},
 	}
@@ -389,6 +391,8 @@ func RootCommand(streams api.Streams, backend api.Service) *cobra.Command { //no
 	c.Flags().MarkHidden("no-ansi") //nolint:errcheck
 	c.Flags().BoolVar(&verbose, "verbose", false, "Show more output")
 	c.Flags().MarkHidden("verbose") //nolint:errcheck
+	c.Flags().BoolVar(&dryRun, "dry-run", false, "Execute command in dry run mode")
+	c.Flags().MarkHidden("dry-run") //nolint:errcheck
 	return c
 }
 

+ 1 - 0
docs/reference/compose.md

@@ -41,6 +41,7 @@ Docker Compose
 |:-----------------------|:--------------|:--------|:----------------------------------------------------------------------------------------------------|
 | `--ansi`               | `string`      | `auto`  | Control when to print ANSI control characters ("never"\|"always"\|"auto")                           |
 | `--compatibility`      |               |         | Run compose in backward compatibility mode                                                          |
+| `--dry-run`            |               |         | Execute command in dry run mode                                                                     |
 | `--env-file`           | `string`      |         | Specify an alternate environment file.                                                              |
 | `-f`, `--file`         | `stringArray` |         | Compose configuration files                                                                         |
 | `--parallel`           | `int`         | `-1`    | Control max parallelism, -1 for unlimited                                                           |

+ 10 - 0
docs/reference/docker_compose.yaml

@@ -178,6 +178,16 @@ options:
       experimentalcli: false
       kubernetes: false
       swarm: false
+    - option: dry-run
+      value_type: bool
+      default_value: "false"
+      description: Execute command in dry run mode
+      deprecated: false
+      hidden: false
+      experimental: false
+      experimentalcli: false
+      kubernetes: false
+      swarm: false
     - option: env-file
       value_type: string
       description: Specify an alternate environment file.

+ 2 - 0
pkg/api/api.go

@@ -77,6 +77,8 @@ type Service interface {
 	Images(ctx context.Context, projectName string, options ImagesOptions) ([]ImageSummary, error)
 	// MaxConcurrency defines upper limit for concurrent operations against engine API
 	MaxConcurrency(parallel int)
+	// DryRunMode defines if dry run applies to the command
+	DryRunMode(dryRun bool)
 	// Watch services' development context and sync/notify/rebuild/restart on changes
 	Watch(ctx context.Context, project *types.Project, services []string, options WatchOptions) error
 }

+ 5 - 0
pkg/api/proxy.go

@@ -52,6 +52,7 @@ type ServiceProxy struct {
 	ImagesFn             func(ctx context.Context, projectName string, options ImagesOptions) ([]ImageSummary, error)
 	WatchFn              func(ctx context.Context, project *types.Project, services []string, options WatchOptions) error
 	MaxConcurrencyFn     func(parallel int)
+	DryRunModeFn         func(dryRun bool)
 	interceptors         []Interceptor
 }
 
@@ -324,3 +325,7 @@ func (s *ServiceProxy) Watch(ctx context.Context, project *types.Project, servic
 func (s *ServiceProxy) MaxConcurrency(i int) {
 	s.MaxConcurrencyFn(i)
 }
+
+func (s *ServiceProxy) DryRunMode(dryRun bool) {
+	s.DryRunModeFn(dryRun)
+}

+ 6 - 0
pkg/compose/compose.go

@@ -43,12 +43,14 @@ func NewComposeService(dockerCli command.Cli) api.Service {
 	return &composeService{
 		dockerCli:      dockerCli,
 		maxConcurrency: -1,
+		dryRun:         false,
 	}
 }
 
 type composeService struct {
 	dockerCli      command.Cli
 	maxConcurrency int
+	dryRun         bool
 }
 
 func (s *composeService) apiClient() client.APIClient {
@@ -63,6 +65,10 @@ func (s *composeService) MaxConcurrency(i int) {
 	s.maxConcurrency = i
 }
 
+func (s *composeService) DryRunMode(dryRun bool) {
+	s.dryRun = dryRun
+}
+
 func (s *composeService) stdout() *streams.Out {
 	return s.dockerCli.Out()
 }