1
1
package cmd
2
2
3
3
import (
4
+ "fmt"
4
5
errutil "github.com/semaphoreci/artifact/pkg/errors"
5
6
"github.com/semaphoreci/artifact/pkg/files"
6
7
"github.com/semaphoreci/artifact/pkg/hub"
@@ -18,7 +19,7 @@ artifact push. With artifact pull you can download them to the current directory
18
19
to use them in a later phase, debug, or getting the results.` ,
19
20
}
20
21
21
- func runPullForCategory (cmd * cobra.Command , args []string , resolver * files.PathResolver ) (* files.ResolvedPath , error ) {
22
+ func runPullForCategory (cmd * cobra.Command , args []string , resolver * files.PathResolver ) (* files.ResolvedPath , * storage. PullStats , error ) {
22
23
destinationOverride , err := cmd .Flags ().GetString ("destination" )
23
24
errutil .Check (err )
24
25
@@ -49,7 +50,7 @@ func NewPullJobCmd() *cobra.Command {
49
50
resolver , err := files .NewPathResolver (files .ResourceTypeJob , jobId )
50
51
errutil .Check (err )
51
52
52
- paths , err := runPullForCategory (cmd , args , resolver )
53
+ paths , stats , err := runPullForCategory (cmd , args , resolver )
53
54
if err != nil {
54
55
log .Errorf ("Error pulling artifact: %v\n " , err )
55
56
log .Error ("Please check if the artifact you are trying to pull exists.\n " )
@@ -60,6 +61,7 @@ func NewPullJobCmd() *cobra.Command {
60
61
log .Info ("Successfully pulled artifact for current job.\n " )
61
62
log .Infof ("* Remote source: '%s'.\n " , paths .Source )
62
63
log .Infof ("* Local destination: '%s'.\n " , paths .Destination )
64
+ log .Infof ("Pulled %d files. Total of %s\n " , stats .FileCount , formatBytes (stats .TotalSize ))
63
65
},
64
66
}
65
67
@@ -83,7 +85,7 @@ func NewPullWorkflowCmd() *cobra.Command {
83
85
resolver , err := files .NewPathResolver (files .ResourceTypeWorkflow , workflowId )
84
86
errutil .Check (err )
85
87
86
- paths , err := runPullForCategory (cmd , args , resolver )
88
+ paths , stats , err := runPullForCategory (cmd , args , resolver )
87
89
if err != nil {
88
90
log .Errorf ("Error pulling artifact: %v\n " , err )
89
91
log .Error ("Please check if the artifact you are trying to pull exists.\n " )
@@ -94,6 +96,7 @@ func NewPullWorkflowCmd() *cobra.Command {
94
96
log .Info ("Successfully pulled artifact for current workflow.\n " )
95
97
log .Infof ("* Remote source: '%s'.\n " , paths .Source )
96
98
log .Infof ("* Local destination: '%s'.\n " , paths .Destination )
99
+ log .Infof ("Pulled %d files. Total of %s\n " , stats .FileCount , formatBytes (stats .TotalSize ))
97
100
},
98
101
}
99
102
@@ -117,7 +120,7 @@ func NewPullProjectCmd() *cobra.Command {
117
120
resolver , err := files .NewPathResolver (files .ResourceTypeProject , projectId )
118
121
errutil .Check (err )
119
122
120
- paths , err := runPullForCategory (cmd , args , resolver )
123
+ paths , stats , err := runPullForCategory (cmd , args , resolver )
121
124
if err != nil {
122
125
log .Errorf ("Error pulling artifact: %v\n " , err )
123
126
log .Error ("Please check if the artifact you are trying to pull exists.\n " )
@@ -128,6 +131,7 @@ func NewPullProjectCmd() *cobra.Command {
128
131
log .Info ("Successfully pulled artifact for current project.\n " )
129
132
log .Infof ("* Remote source: '%s'.\n " , paths .Source )
130
133
log .Infof ("* Local destination: '%s'.\n " , paths .Destination )
134
+ log .Infof ("Pulled %d files. Total of %s\n " , stats .FileCount , formatBytes (stats .TotalSize ))
131
135
},
132
136
}
133
137
@@ -137,6 +141,20 @@ func NewPullProjectCmd() *cobra.Command {
137
141
return cmd
138
142
}
139
143
144
+ // formatBytes converts bytes to human readable format
145
+ func formatBytes (bytes int64 ) string {
146
+ const unit = 1024
147
+ if bytes < unit {
148
+ return fmt .Sprintf ("%d B" , bytes )
149
+ }
150
+ div , exp := int64 (unit ), 0
151
+ for n := bytes / unit ; n >= unit ; n /= unit {
152
+ div *= unit
153
+ exp ++
154
+ }
155
+ return fmt .Sprintf ("%.1f %cB" , float64 (bytes )/ float64 (div ), "KMGTPE" [exp ])
156
+ }
157
+
140
158
func init () {
141
159
rootCmd .AddCommand (pullCmd )
142
160
pullCmd .AddCommand (NewPullJobCmd ())
0 commit comments