4
4
"bytes"
5
5
"context"
6
6
"fmt"
7
- "github.com/linuxsuren/http-downloader/pkg/common"
8
- "github.com/linuxsuren/http-downloader/pkg/log"
9
7
"io"
10
8
"io/fs"
11
9
"net/http"
@@ -16,6 +14,9 @@ import (
16
14
"strings"
17
15
"sync"
18
16
17
+ "github.com/linuxsuren/http-downloader/pkg/common"
18
+ "github.com/linuxsuren/http-downloader/pkg/log"
19
+
19
20
"github.com/AlecAivazis/survey/v2"
20
21
"github.com/linuxsuren/http-downloader/pkg/exec"
21
22
"golang.org/x/net/html"
@@ -25,6 +26,7 @@ import (
25
26
"github.com/linuxsuren/http-downloader/pkg/installer"
26
27
"github.com/linuxsuren/http-downloader/pkg/net"
27
28
"github.com/spf13/cobra"
29
+ "github.com/spf13/pflag"
28
30
"github.com/spf13/viper"
29
31
"gopkg.in/yaml.v3"
30
32
)
@@ -43,6 +45,7 @@ func newGetCmd(ctx context.Context) (cmd *cobra.Command) {
43
45
// set flags
44
46
flags := cmd .Flags ()
45
47
opt .addFlags (flags )
48
+ opt .addPlatformFlags (flags )
46
49
flags .StringVarP (& opt .Output , "output" , "o" , "" , "Write output to <file> instead of stdout." )
47
50
flags .BoolVarP (& opt .AcceptPreRelease , "accept-preRelease" , "" , false ,
48
51
"If you accept preRelease as the binary asset from GitHub" )
@@ -63,8 +66,6 @@ func newGetCmd(ctx context.Context) (cmd *cobra.Command) {
63
66
`Download file with multi-threads. It only works when its value is bigger than 1` )
64
67
flags .BoolVarP (& opt .KeepPart , "keep-part" , "" , false ,
65
68
"If you want to keep the part files instead of deleting them" )
66
- flags .StringVarP (& opt .OS , "os" , "" , runtime .GOOS , "The OS of target binary file" )
67
- flags .StringVarP (& opt .Arch , "arch" , "" , runtime .GOARCH , "The arch of target binary file" )
68
69
flags .BoolVarP (& opt .PrintSchema , "print-schema" , "" , false ,
69
70
"Print the schema of HDConfig if the flag is true without other function" )
70
71
flags .BoolVarP (& opt .PrintVersion , "print-version" , "" , false ,
@@ -226,6 +227,11 @@ func (o *downloadOption) preRunE(cmd *cobra.Command, args []string) (err error)
226
227
return
227
228
}
228
229
230
+ func (o * downloadOption ) addPlatformFlags (flags * pflag.FlagSet ) {
231
+ flags .StringVarP (& o .OS , "os" , "" , runtime .GOOS , "The OS of target binary file" )
232
+ flags .StringVarP (& o .Arch , "arch" , "" , runtime .GOARCH , "The arch of target binary file" )
233
+ }
234
+
229
235
func findAnchor (n * html.Node ) (items []string ) {
230
236
if n .Type == html .ElementNode && n .Data == "a" {
231
237
for _ , a := range n .Attr {
@@ -295,8 +301,8 @@ func (o *downloadOption) runE(cmd *cobra.Command, args []string) (err error) {
295
301
296
302
targetURL := o .URL
297
303
if o .ProxyGitHub != "" {
298
- targetURL = strings .Replace (targetURL , "github.com" , fmt .Sprintf ("%s/github.com" , o .ProxyGitHub ), 1 )
299
- targetURL = strings .Replace (targetURL , "raw.githubusercontent.com" , fmt .Sprintf ("%s/https://raw.githubusercontent.com" , o .ProxyGitHub ), 1 )
304
+ targetURL = strings .Replace (targetURL , "https:// github.com" , fmt .Sprintf ("https:// %s/github.com" , o .ProxyGitHub ), 1 )
305
+ targetURL = strings .Replace (targetURL , "https:// raw.githubusercontent.com" , fmt .Sprintf ("https:// %s/https://raw.githubusercontent.com" , o .ProxyGitHub ), 1 )
300
306
}
301
307
logger .Printf ("start to download from %s\n " , targetURL )
302
308
var suggestedFilenameAware net.SuggestedFilenameAware
0 commit comments