Skip to content

Commit

Permalink
Print download destination and fix progressbar
Browse files Browse the repository at this point in the history
  • Loading branch information
gnojus committed Dec 29, 2019
1 parent b793d04 commit 08e37b4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"errors"
"fmt"
"github.com/Nojus297/wedl/transfer"
"github.com/cheggaaa/pb"
"io"
Expand All @@ -22,18 +23,26 @@ func Eval(opts map[string]interface{}) (err error) {
parsed.Output = transfer.FilenameFromUrl(resp.Request.URL.String())
}
if parsed.Output == "" {
return errors.New("Canot find filename")
return errors.New("Canot find any filename")
}
writer, err := transfer.GetWriter(parsed.Output, parsed.Path, parsed.Force)
if err != nil {
return
}
if !parsed.Silent {
output := parsed.Output
if output == "-" {
output = "stdout"
}
fmt.Fprintf(os.Stderr, "Writing to %s\n", output)
bar := pb.New64(resp.ContentLength).SetUnits(pb.U_BYTES_DEC)
bar.Output = os.Stderr
bar.Start()
writer = bar.NewProxyWriter(writer)
io.Copy(writer, resp.Body)
bar.Finish()
} else {
io.Copy(writer, resp.Body)
}
io.Copy(writer, resp.Body)
return
}

0 comments on commit 08e37b4

Please sign in to comment.