Skip to content

Commit

Permalink
Introduce HEADERS to fastget command
Browse files Browse the repository at this point in the history
  • Loading branch information
pgollangi committed Sep 9, 2020
1 parent 49de2b3 commit 2c6dc75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"time"

"github.com/MakeNowJust/heredoc"
Expand All @@ -30,7 +31,9 @@ var RootCmd = &cobra.Command{
SilenceErrors: true,
SilenceUsage: true,
Example: heredoc.Doc(`
$ fastget https://file.example.com
$ fastget https://file.example.com // Basic Usage
$ fastget http://speedtest.tele2.net/10MB.zip -H "Authorization: Basic ASYFASUF" // Custom Header
$ fastget http://speedtest.tele2.net/10MB.zip -w 6 // Increased no. of workers
$ fastget -v
`),
RunE: runCommand,
Expand All @@ -52,6 +55,8 @@ func runCommand(cmd *cobra.Command, args []string) error {

threads, _ := cmd.Flags().GetInt("workers")

headers, _ := cmd.Flags().GetStringArray("header")

url := args[0]

fg, err := fastget.NewFastGetter(url)
Expand All @@ -61,6 +66,12 @@ func runCommand(cmd *cobra.Command, args []string) error {
}
fg.Workers = threads

for _, header := range headers {
split := strings.Split(header, ":")
fg.Headers[split[0]] = split[1]
fmt.Println(header)
}

fmt.Println("Initializing download..")

mpbars := make(map[int]*barStatus)
Expand Down Expand Up @@ -129,6 +140,7 @@ func init() {
RootCmd.Flags().BoolP("debug", "d", false, "show debug information")
RootCmd.Flags().IntP("workers", "w", 3, "use <n> parellel threads")
RootCmd.Flags().StringP("output", "o", ".", "output file to be written")
RootCmd.Flags().StringArrayP("header", "H", []string{}, "output file to be written")
}

func executeVersionCmd() {
Expand Down
1 change: 1 addition & 0 deletions fastget.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewFastGetter(fileURL string) (*FastGetter, error) {
FileURL: fileURL,
Workers: 3,
OutputFile: path.Base(fileURL),
Headers: make(map[string]string),
}
return fg, nil
}
Expand Down

0 comments on commit 2c6dc75

Please sign in to comment.