From e42b7f6a656e30c749e6582923cd4e723a98b6bc Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 8 Jun 2022 10:55:52 +0300 Subject: [PATCH] [#1484] neofs-cli: Print progress bar after the header has been sent Make it similar to `object get`. Signed-off-by: Evgenii Stratonikov --- cmd/neofs-cli/internal/client/client.go | 12 ++++++++++++ cmd/neofs-cli/modules/object/put.go | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/neofs-cli/internal/client/client.go b/cmd/neofs-cli/internal/client/client.go index d76e60527..3ae06a03e 100644 --- a/cmd/neofs-cli/internal/client/client.go +++ b/cmd/neofs-cli/internal/client/client.go @@ -299,6 +299,8 @@ type PutObjectPrm struct { hdr *object.Object rdr io.Reader + + headerCallback func(*object.Object) } // SetHeader sets object header. @@ -311,6 +313,12 @@ func (x *PutObjectPrm) SetPayloadReader(rdr io.Reader) { x.rdr = rdr } +// SetHeaderCallback sets callback which is called on the object after the header is received +// but before the payload is written. +func (x *PutObjectPrm) SetHeaderCallback(f func(*object.Object)) { + x.headerCallback = f +} + // PutObjectRes groups the resulting values of PutObject operation. type PutObjectRes struct { id oid.ID @@ -347,6 +355,10 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) { wrt.WithXHeaders(prm.xHeaders...) if wrt.WriteHeader(*prm.hdr) { + if prm.headerCallback != nil { + prm.headerCallback(prm.hdr) + } + sz := prm.hdr.PayloadSize() if data := prm.hdr.Payload(); len(data) > 0 { diff --git a/cmd/neofs-cli/modules/object/put.go b/cmd/neofs-cli/modules/object/put.go index 9022080ed..1c4a7fbe1 100644 --- a/cmd/neofs-cli/modules/object/put.go +++ b/cmd/neofs-cli/modules/object/put.go @@ -128,7 +128,9 @@ func putObject(cmd *cobra.Command, _ []string) { p = pb.New64(fi.Size()) p.Output = cmd.OutOrStdout() prm.SetPayloadReader(p.NewProxyReader(f)) - p.Start() + prm.SetHeaderCallback(func(o *object.Object) { + p.Start() + }) } }