From 9e7e9a937d6ab38bc51a855addff77d1391bbd6b Mon Sep 17 00:00:00 2001 From: yunfeiyangbuaa Date: Thu, 22 Aug 2019 16:49:55 +0800 Subject: [PATCH] modify dfget output Signed-off-by: yunfeiyangbuaa --- cmd/dfget/app/root.go | 6 +++--- cmd/dfget/app/root_test.go | 4 ++-- dfget/core/core.go | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/dfget/app/root.go b/cmd/dfget/app/root.go index ee34d395a..5c5ccf569 100644 --- a/cmd/dfget/app/root.go +++ b/cmd/dfget/app/root.go @@ -299,12 +299,12 @@ func handleNodes() error { func resultMsg(cfg *config.Config, end time.Time, e *errortypes.DfError) string { if e != nil { - return fmt.Sprintf("download FAIL(%d) cost:%.3fs length:%d reason:%d error:%v", + return fmt.Sprintf("download FAIL(%d)\ncost:%.3fs length:%d\nreason:%d\nerror:%v", e.Code, end.Sub(cfg.StartTime).Seconds(), cfg.RV.FileLength, cfg.BackSourceReason, e) } - return fmt.Sprintf("download SUCCESS(0) cost:%.3fs length:%d reason:%d", - end.Sub(cfg.StartTime).Seconds(), cfg.RV.FileLength, cfg.BackSourceReason) + return fmt.Sprintf("download SUCCESS !\ncost:%.3fs length:%d", + end.Sub(cfg.StartTime).Seconds(), cfg.RV.FileLength) } // Execute will process dfget. diff --git a/cmd/dfget/app/root_test.go b/cmd/dfget/app/root_test.go index b2e0a5517..8e30ad04d 100644 --- a/cmd/dfget/app/root_test.go +++ b/cmd/dfget/app/root_test.go @@ -153,10 +153,10 @@ func (suit *dfgetSuit) TestResultMsg() { end := cfg.StartTime.Add(100 * time.Millisecond) msg := resultMsg(cfg, end, nil) - suit.Equal(msg, "download SUCCESS(0) cost:0.100s length:-1 reason:0") + suit.Equal(msg, "download SUCCESS !\ncost:0.100s length:-1") msg = resultMsg(cfg, end, errortypes.New(1, "TestFail")) - suit.Equal(msg, "download FAIL(1) cost:0.100s length:-1 reason:0 error:"+ + suit.Equal(msg, "download FAIL(1)\ncost:0.100s length:-1\nreason:0\nerror:"+ `{"Code":1,"Msg":"TestFail"}`) } diff --git a/dfget/core/core.go b/dfget/core/core.go index 8824eed3b..2f8d64f0e 100644 --- a/dfget/core/core.go +++ b/dfget/core/core.go @@ -79,8 +79,9 @@ func Start(cfg *config.Config) *errortypes.DfError { // prepare the RV-related information and create the corresponding files. func prepare(cfg *config.Config) (err error) { - fmt.Printf("dfget version:%s", version.DFGetVersion) - fmt.Printf("workspace:%s sign:%s", cfg.WorkHome, cfg.Sign) + printer.Printf("dfget version:%s", version.DFGetVersion) + printer.Printf("workspace:%s", cfg.Sign) + printer.Printf("sign:%s", cfg.Sign) logrus.Infof("target file path:%s", cfg.Output) rv := &cfg.RV @@ -160,7 +161,7 @@ func registerToSuperNode(cfg *config.Config, register regist.SupernodeRegister) panic(e.Error()) } cfg.RV.FileLength = result.FileLength - fmt.Printf("client:%s connected to node:%s", cfg.RV.LocalIP, result.Node) + printer.Printf("client:%s connected to node:%s", cfg.RV.LocalIP, result.Node) return result, nil } @@ -170,7 +171,7 @@ func downloadFile(cfg *config.Config, supernodeAPI api.SupernodeAPI, if cfg.BackSourceReason > 0 { getter = backDown.NewBackDownloader(cfg, result) } else { - fmt.Printf("start download by dragonfly") + printer.Printf("start download by dragonfly...") getter = p2pDown.NewP2PDownloader(cfg, supernodeAPI, register, result) }