66 "github.com/linuxsuren/http-downloader/pkg"
77 "github.com/linuxsuren/http-downloader/pkg/installer"
88 "github.com/spf13/cobra"
9+ "github.com/spf13/viper"
910 "gopkg.in/yaml.v2"
1011 "net/http"
1112 "net/url"
@@ -29,29 +30,23 @@ func newGetCmd(ctx context.Context) (cmd *cobra.Command) {
2930
3031 // set flags
3132 flags := cmd .Flags ()
33+ opt .addFlags (flags )
3234 flags .StringVarP (& opt .Output , "output" , "o" , "" , "Write output to <file> instead of stdout." )
33- flags .BoolVarP (& opt .Fetch , "fetch" , "" , true ,
34- "If fetch the latest config from https://github.com/LinuxSuRen/hd-home" )
3535 flags .BoolVarP (& opt .AcceptPreRelease , "accept-preRelease" , "" , false ,
3636 "If you accept preRelease as the binary asset from GitHub" )
3737 flags .BoolVarP (& opt .AcceptPreRelease , "pre" , "" , false ,
3838 "Same with option --accept-preRelease" )
39- flags .StringVarP (& opt .ProxyGitHub , "proxy-github" , "" , "" ,
40- `The proxy address of github.com, the proxy address will be the prefix of the final address.
41- Available proxy: gh.api.99988866.xyz
42- Thanks to https://github.com/hunshcn/gh-proxy` )
4339
4440 flags .IntVarP (& opt .Timeout , "time" , "" , 10 ,
4541 `The default timeout in seconds with the HTTP request` )
4642 flags .IntVarP (& opt .MaxAttempts , "max-attempts" , "" , 10 ,
4743 `Max times to attempt to download, zero means there's no retry action'` )
4844 flags .BoolVarP (& opt .ShowProgress , "show-progress" , "" , true , "If show the progress of download" )
4945 flags .Int64VarP (& opt .ContinueAt , "continue-at" , "" , - 1 , "ContinueAt" )
50- flags .IntVarP (& opt .Thread , "thread" , "t" , 0 ,
46+ flags .IntVarP (& opt .Thread , "thread" , "t" , viper . GetInt ( "thread" ) ,
5147 `Download file with multi-threads. It only works when its value is bigger than 1` )
5248 flags .BoolVarP (& opt .KeepPart , "keep-part" , "" , false ,
5349 "If you want to keep the part files instead of deleting them" )
54- flags .StringVarP (& opt .Provider , "provider" , "" , ProviderGitHub , "The file provider" )
5550 flags .StringVarP (& opt .OS , "os" , "" , runtime .GOOS , "The OS of target binary file" )
5651 flags .StringVarP (& opt .Arch , "arch" , "" , runtime .GOARCH , "The arch of target binary file" )
5752 flags .BoolVarP (& opt .PrintSchema , "print-schema" , "" , false ,
@@ -63,26 +58,25 @@ Thanks to https://github.com/hunshcn/gh-proxy`)
6358
6459 _ = cmd .RegisterFlagCompletionFunc ("proxy-github" , ArrayCompletion ("gh.api.99988866.xyz" ,
6560 "ghproxy.com" , "mirror.ghproxy.com" ))
66- _ = cmd .RegisterFlagCompletionFunc ("provider" , ArrayCompletion (ProviderGitHub , "gitee" ))
61+ _ = cmd .RegisterFlagCompletionFunc ("provider" , ArrayCompletion (ProviderGitHub , ProviderGitee ))
6762 return
6863}
6964
7065type downloadOption struct {
71- URL string
72- Output string
73- ShowProgress bool
74- Fetch bool
66+ searchOption
67+
68+ URL string
69+ Output string
70+ ShowProgress bool
7571 Timeout int
7672 MaxAttempts int
7773 AcceptPreRelease bool
7874 RoundTripper http.RoundTripper
79- ProxyGitHub string
8075
8176 ContinueAt int64
8277
83- Provider string
84- Arch string
85- OS string
78+ Arch string
79+ OS string
8680
8781 Thread int
8882 KeepPart bool
@@ -101,6 +95,8 @@ type downloadOption struct {
10195const (
10296 // ProviderGitHub represents https://github.com
10397 ProviderGitHub = "github"
98+ // ProviderGitee represents https://gitee.com
99+ ProviderGitee = "gitee"
104100)
105101
106102func (o * downloadOption ) preRunE (cmd * cobra.Command , args []string ) (err error ) {
0 commit comments