@@ -24,6 +24,7 @@ import (
2424 "path/filepath"
2525 "strings"
2626
27+ "github.com/docker/compose/v2/pkg/progress"
2728 "golang.org/x/sync/errgroup"
2829
2930 "github.com/docker/cli/cli/command"
@@ -43,6 +44,12 @@ const (
4344)
4445
4546func (s * composeService ) Copy (ctx context.Context , projectName string , options api.CopyOptions ) error {
47+ return progress .Run (ctx , func (ctx context.Context ) error {
48+ return s .copy (ctx , projectName , options )
49+ }, s .stderr ())
50+ }
51+
52+ func (s * composeService ) copy (ctx context.Context , projectName string , options api.CopyOptions ) error {
4653 projectName = strings .ToLower (projectName )
4754 srcService , srcPath := splitCpArg (options .Source )
4855 destService , dstPath := splitCpArg (options .Destination )
@@ -78,18 +85,33 @@ func (s *composeService) Copy(ctx context.Context, projectName string, options a
7885 return err
7986 }
8087
88+ w := progress .ContextWriter (ctx )
8189 g := errgroup.Group {}
8290 for _ , cont := range containers {
8391 container := cont
8492 g .Go (func () error {
93+ name := getCanonicalContainerName (container )
94+ var msg string
95+ if direction == fromService {
96+ msg = fmt .Sprintf ("copy %s:%s to %s" , name , srcPath , dstPath )
97+ } else {
98+ msg = fmt .Sprintf ("copy %s to %s:%s" , srcPath , name , dstPath )
99+ }
100+ w .Event (progress.Event {
101+ ID : name ,
102+ Text : msg ,
103+ Status : progress .Working ,
104+ StatusText : "Copying" ,
105+ })
85106 if err := copyFunc (ctx , container .ID , srcPath , dstPath , options ); err != nil {
86107 return err
87108 }
88- fromOrInside := "inside"
89- if direction == fromService {
90- fromOrInside = "from"
91- }
92- fmt .Fprintf (s .stderr (), "Copy %s to path %s %s %s service container\n " , srcPath , dstPath , fromOrInside , getCanonicalContainerName (container ))
109+ w .Event (progress.Event {
110+ ID : name ,
111+ Text : msg ,
112+ Status : progress .Done ,
113+ StatusText : "Copied" ,
114+ })
93115 return nil
94116 })
95117 }
0 commit comments