@@ -3,6 +3,7 @@ package main
33import (
44 "bufio"
55 "context"
6+ "errors"
67 "fmt"
78 "log"
89 "net/url"
@@ -21,6 +22,8 @@ import (
2122
2223var version string
2324
25+ var HeaderSlice []got.GotHeader
26+
2427func main () {
2528
2629 // New context.
@@ -67,6 +70,11 @@ func main() {
6770 Usage : "Chunks that will be downloaded concurrently." ,
6871 Aliases : []string {"c" },
6972 },
73+ & cli.StringSliceFlag {
74+ Name : "header" ,
75+ Usage : "Set these HTTP-Headers on the requests. The format has to be Key: Value" ,
76+ Aliases : []string {"H" },
77+ },
7078 },
7179 Version : version ,
7280 Authors : []* cli.Author {
@@ -100,20 +108,24 @@ func run(ctx context.Context, c *cli.Context) error {
100108
101109 // 55 is just an estimation of the text showed with the progress.
102110 // it's working fine with $COLUMNS >= 47
103- // TODO: hide progress bar on terminal size of $COLUMNS <= 46
104111 p .Width = getWidth () - 55
105112
106113 perc , err := progress .GetPercentage (float64 (d .Size ()), float64 (d .TotalSize ()))
107114 if err != nil {
108115 perc = 100
109116 }
110117
118+ var bar string
119+ if getWidth () <= 46 {
120+ bar = ""
121+ } else {
122+ bar = r + color (p .GetBar (perc , 100 )) + l
123+ }
124+
111125 fmt .Printf (
112- " %6.2f%% %s%s%s %s/%s @ %s/s%s\r " ,
126+ " %6.2f%% %s %s/%s @ %s/s%s\r " ,
113127 perc ,
114- r ,
115- color (p .GetBar (perc , 100 )),
116- l ,
128+ bar ,
117129 humanize .Bytes (d .Size ()),
118130 humanize .Bytes (d .TotalSize ()),
119131 humanize .Bytes (d .Speed ()),
@@ -157,6 +169,18 @@ func run(ctx context.Context, c *cli.Context) error {
157169 }
158170 }
159171
172+ if c .StringSlice ("header" ) != nil {
173+ header := c .StringSlice ("header" )
174+
175+ for _ , h := range header {
176+ split := strings .SplitN (h , ":" , 2 )
177+ if len (split ) == 1 {
178+ return errors .New ("malformatted header " + h )
179+ }
180+ HeaderSlice = append (HeaderSlice , got.GotHeader {Key : split [0 ], Value : strings .TrimSpace (split [1 ])})
181+ }
182+ }
183+
160184 // Download from args.
161185 for _ , url := range c .Args ().Slice () {
162186
@@ -211,6 +235,7 @@ func download(ctx context.Context, c *cli.Context, g *got.Got, url string) (err
211235 URL : url ,
212236 Dir : c .String ("dir" ),
213237 Dest : c .String ("output" ),
238+ Header : HeaderSlice ,
214239 Interval : 150 ,
215240 ChunkSize : c .Uint64 ("size" ),
216241 Concurrency : c .Uint ("concurrency" ),
0 commit comments