Debian Codegraph @

v3/cmd/grab/main.go

raw symbols SCIP
1 package main
2
3 import (
4 "context"
5 "fmt"
6 "os"
7
8 "github.com/cavaliergopher/grab/v3/pkg/grabui"
9 )
10
11 func main() {
12 // validate command args
13 if len(os.Args) < 2 {
14 fmt.Fprintf(os.Stderr, "usage: %s url...\n", os.Args[0])
15 os.Exit(1)
16 }
17 urls := os.Args[1:]
18
19 // download files
20 respch, err := grabui.GetBatch(context.Background(), 0, ".", urls...)
21 if err != nil {
22 fmt.Fprint(os.Stderr, err)
23 os.Exit(1)
24 }
25
26 // return the number of failed downloads as exit code
27 failed := 0
28 for resp := range respch {
29 if resp.Err() != nil {
30 failed++
31 }
32 }
33 os.Exit(failed)
34 }