Skip to content

Commit 45def51

Browse files
ndeloofglours
authored andcommitted
make DRYRUN_PREFIX a display attribute, move DryRunClient out of pkg/api
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent aff5c11 commit 45def51

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

cmd/display/dryrun.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package display
18+
19+
const (
20+
DRYRUN_PREFIX = " DRY-RUN MODE - "
21+
)

cmd/display/plain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (p *plainWriter) Start(ctx context.Context, operation string) {
4141
func (p *plainWriter) Event(e api.Resource) {
4242
prefix := ""
4343
if p.dryRun {
44-
prefix = api.DRYRUN_PREFIX
44+
prefix = DRYRUN_PREFIX
4545
}
4646
_, _ = fmt.Fprintln(p.out, prefix, e.ID, e.Text, e.Details)
4747
}

cmd/display/tty.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func (w *ttyWriter) lineText(t task, pad string, terminalWidth, statusPadding in
286286
}
287287
prefix := ""
288288
if dryRun {
289-
prefix = PrefixColor(api.DRYRUN_PREFIX)
289+
prefix = PrefixColor(DRYRUN_PREFIX)
290290
}
291291

292292
elapsed := endTime.Sub(t.startTime).Seconds()

pkg/compose/compose.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/docker/cli/cli/config/configfile"
3232
"github.com/docker/cli/cli/flags"
3333
"github.com/docker/cli/cli/streams"
34+
"github.com/docker/compose/v2/pkg/dryrun"
3435
"github.com/docker/docker/api/types/container"
3536
"github.com/docker/docker/api/types/filters"
3637
"github.com/docker/docker/api/types/network"
@@ -173,7 +174,7 @@ func WithDryRun(s *composeService) error {
173174
options := flags.NewClientOptions()
174175
options.Context = s.dockerCli.CurrentContext()
175176
err = cli.Initialize(options, command.WithInitializeClient(func(cli *command.DockerCli) (client.APIClient, error) {
176-
return api.NewDryRunClient(s.apiClient(), s.dockerCli)
177+
return dryrun.NewDryRunClient(s.apiClient(), s.dockerCli)
177178
}))
178179
if err != nil {
179180
return err
Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package api
17+
package dryrun
1818

1919
import (
2020
"bytes"
@@ -50,10 +50,6 @@ import (
5050
specs "github.com/opencontainers/image-spec/specs-go/v1"
5151
)
5252

53-
const (
54-
DRYRUN_PREFIX = " DRY-RUN MODE - "
55-
)
56-
5753
var _ client.APIClient = &DryRunClient{}
5854

5955
// DryRunClient implements APIClient by delegating to implementation functions. This allows lazy init and per-method overrides
@@ -192,28 +188,17 @@ func (d *DryRunClient) ContainerUnpause(ctx context.Context, container string) e
192188
func (d *DryRunClient) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, containerType.PathStat, error) {
193189
rc := io.NopCloser(strings.NewReader(""))
194190
if _, err := d.ContainerStatPath(ctx, container, srcPath); err != nil {
195-
return rc, containerType.PathStat{}, fmt.Errorf(" %s Could not find the file %s in container %s", DRYRUN_PREFIX, srcPath, container)
191+
return rc, containerType.PathStat{}, fmt.Errorf("could not find the file %s in container %s", srcPath, container)
196192
}
197193
return rc, containerType.PathStat{}, nil
198194
}
199195

200196
func (d *DryRunClient) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options containerType.CopyToContainerOptions) error {
201-
if _, err := d.ContainerStatPath(ctx, container, path); err != nil {
202-
return fmt.Errorf(" %s Could not find the file %s in container %s", DRYRUN_PREFIX, path, container)
203-
}
204197
return nil
205198
}
206199

207200
func (d *DryRunClient) ImageBuild(ctx context.Context, reader io.Reader, options build.ImageBuildOptions) (build.ImageBuildResponse, error) {
208-
jsonMessage, err := json.Marshal(&jsonmessage.JSONMessage{
209-
Status: fmt.Sprintf("%[1]sSuccessfully built: dryRunID\n%[1]sSuccessfully tagged: %[2]s\n", DRYRUN_PREFIX, options.Tags[0]),
210-
Progress: &jsonmessage.JSONProgress{},
211-
ID: "",
212-
})
213-
if err != nil {
214-
return build.ImageBuildResponse{}, err
215-
}
216-
rc := io.NopCloser(bytes.NewReader(jsonMessage))
201+
rc := io.NopCloser(bytes.NewReader(nil))
217202

218203
return build.ImageBuildResponse{
219204
Body: rc,
@@ -321,12 +306,10 @@ func (d *DryRunClient) ContainerExecCreate(ctx context.Context, container string
321306
}
322307

323308
func (d *DryRunClient) ContainerExecStart(ctx context.Context, execID string, config containerType.ExecStartOptions) error {
324-
v, ok := d.execs.LoadAndDelete(execID)
309+
_, ok := d.execs.LoadAndDelete(execID)
325310
if !ok {
326311
return fmt.Errorf("invalid exec ID %q", execID)
327312
}
328-
details := v.(execDetails)
329-
fmt.Printf("%sExecuting command %q in %s (detached mode)\n", DRYRUN_PREFIX, details.command, details.container)
330313
return nil
331314
}
332315

0 commit comments

Comments
 (0)