44 "bytes"
55 "context"
66 "fmt"
7- "github.com/linuxsuren/http-downloader/pkg/common"
8- "github.com/linuxsuren/http-downloader/pkg/log"
97 "io"
108 "io/fs"
119 "net/http"
@@ -16,6 +14,9 @@ import (
1614 "strings"
1715 "sync"
1816
17+ "github.com/linuxsuren/http-downloader/pkg/common"
18+ "github.com/linuxsuren/http-downloader/pkg/log"
19+
1920 "github.com/AlecAivazis/survey/v2"
2021 "github.com/linuxsuren/http-downloader/pkg/exec"
2122 "golang.org/x/net/html"
@@ -25,6 +26,7 @@ import (
2526 "github.com/linuxsuren/http-downloader/pkg/installer"
2627 "github.com/linuxsuren/http-downloader/pkg/net"
2728 "github.com/spf13/cobra"
29+ "github.com/spf13/pflag"
2830 "github.com/spf13/viper"
2931 "gopkg.in/yaml.v3"
3032)
@@ -43,6 +45,7 @@ func newGetCmd(ctx context.Context) (cmd *cobra.Command) {
4345 // set flags
4446 flags := cmd .Flags ()
4547 opt .addFlags (flags )
48+ opt .addPlatformFlags (flags )
4649 flags .StringVarP (& opt .Output , "output" , "o" , "" , "Write output to <file> instead of stdout." )
4750 flags .BoolVarP (& opt .AcceptPreRelease , "accept-preRelease" , "" , false ,
4851 "If you accept preRelease as the binary asset from GitHub" )
@@ -63,8 +66,6 @@ func newGetCmd(ctx context.Context) (cmd *cobra.Command) {
6366 `Download file with multi-threads. It only works when its value is bigger than 1` )
6467 flags .BoolVarP (& opt .KeepPart , "keep-part" , "" , false ,
6568 "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" )
6869 flags .BoolVarP (& opt .PrintSchema , "print-schema" , "" , false ,
6970 "Print the schema of HDConfig if the flag is true without other function" )
7071 flags .BoolVarP (& opt .PrintVersion , "print-version" , "" , false ,
@@ -226,6 +227,11 @@ func (o *downloadOption) preRunE(cmd *cobra.Command, args []string) (err error)
226227 return
227228}
228229
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+
229235func findAnchor (n * html.Node ) (items []string ) {
230236 if n .Type == html .ElementNode && n .Data == "a" {
231237 for _ , a := range n .Attr {
@@ -295,8 +301,8 @@ func (o *downloadOption) runE(cmd *cobra.Command, args []string) (err error) {
295301
296302 targetURL := o .URL
297303 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 )
300306 }
301307 logger .Printf ("start to download from %s\n " , targetURL )
302308 var suggestedFilenameAware net.SuggestedFilenameAware
0 commit comments