Skip to content

Commit

Permalink
feat: upgrade the progressbar (#359)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Feb 23, 2023
1 parent 4cfedff commit b8666f1
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 78 deletions.
11 changes: 7 additions & 4 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"runtime"
"strings"
"sync"
"time"

"github.com/linuxsuren/http-downloader/pkg/common"
"github.com/linuxsuren/http-downloader/pkg/log"
Expand Down Expand Up @@ -55,7 +56,7 @@ func newGetCmd(ctx context.Context) (cmd *cobra.Command) {
flags.IntVarP(&opt.Mod, "mod", "", -1, "The file permission, -1 means using the system default")
flags.BoolVarP(&opt.SkipTLS, "skip-tls", "k", false, "Skip the TLS")

flags.IntVarP(&opt.Timeout, "time", "", 10,
flags.DurationVarP(&opt.Timeout, "timeout", "", 15*time.Minute,
`The default timeout in seconds with the HTTP request`)
flags.IntVarP(&opt.MaxAttempts, "max-attempts", "", 10,
`Max times to attempt to download, zero means there's no retry action'`)
Expand Down Expand Up @@ -100,7 +101,7 @@ type downloadOption struct {
Category string
Output string
ShowProgress bool
Timeout int
Timeout time.Duration
NoProxy bool
MaxAttempts int
AcceptPreRelease bool
Expand Down Expand Up @@ -311,7 +312,8 @@ func (o *downloadOption) runE(cmd *cobra.Command, args []string) (err error) {
suggestedFilenameAware = downloader
downloader.WithoutProxy(o.NoProxy).
WithRoundTripper(o.RoundTripper).
WithInsecureSkipVerify(o.SkipTLS)
WithInsecureSkipVerify(o.SkipTLS).
WithTimeout(o.Timeout)
err = downloader.DownloadWithContinue(targetURL, o.Output, o.ContinueAt, -1, 0, o.ShowProgress)
} else {
downloader := &net.MultiThreadDownloader{}
Expand All @@ -320,7 +322,8 @@ func (o *downloadOption) runE(cmd *cobra.Command, args []string) (err error) {
WithShowProgress(o.ShowProgress).
WithoutProxy(o.NoProxy).
WithRoundTripper(o.RoundTripper).
WithInsecureSkipVerify(o.SkipTLS)
WithInsecureSkipVerify(o.SkipTLS).
WithTimeout(o.Timeout)
err = downloader.Download(targetURL, o.Output, o.Thread)
}

Expand Down
9 changes: 5 additions & 4 deletions cmd/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Test_newGetCmd(t *testing.T) {
}, {
name: "pre",
}, {
name: "time",
name: "timeout",
}, {
name: "max-attempts",
}, {
Expand Down Expand Up @@ -63,9 +63,10 @@ func Test_newGetCmd(t *testing.T) {
tt := flags[i]
t.Run(tt.name, func(t *testing.T) {
flag := cmd.Flag(tt.name)
assert.NotNil(t, flag)
assert.NotEmpty(t, flag.Usage)
assert.Equal(t, tt.shorthand, flag.Shorthand)
if assert.NotNil(t, flag, tt.name) {
assert.NotEmpty(t, flag.Usage)
assert.Equal(t, tt.shorthand, flag.Shorthand)
}
})
}
}
Expand Down
17 changes: 12 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/go-git/go-git/v5 v5.4.2
github.com/golang/mock v1.6.0
github.com/google/go-github/v29 v29.0.3
github.com/gosuri/uiprogress v0.0.1
github.com/h2non/gock v1.0.9
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec
github.com/linuxsuren/cobra-extension v0.0.16
Expand All @@ -25,6 +24,15 @@ require (
require (
github.com/antonmedv/expr v1.11.1
github.com/creack/pty v1.1.17
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213
github.com/schollz/progressbar/v3 v3.13.0
)

require (
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
)

require (
Expand All @@ -40,7 +48,6 @@ require (
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/gosuri/uilive v0.0.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand All @@ -49,7 +56,7 @@ require (
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 // indirect
Expand All @@ -65,8 +72,8 @@ require (
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.3.8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
Expand Down
Loading

0 comments on commit b8666f1

Please sign in to comment.