-
Notifications
You must be signed in to change notification settings - Fork 19
/
sos_download.go
45 lines (36 loc) · 923 Bytes
/
sos_download.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cmd
import (
"log"
minio "github.com/minio/minio-go"
"github.com/spf13/cobra"
)
// downloadCmd represents the download command
var downloadCmd = &cobra.Command{
Use: "download <bucket name> <object name> <file path>",
Short: "Download an object from a bucket",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 3 {
return cmd.Usage()
}
minioClient, err := newMinioClient(sosZone)
if err != nil {
return err
}
location, err := minioClient.GetBucketLocation(args[0])
if err != nil {
return err
}
minioClient, err = newMinioClient(location)
if err != nil {
return err
}
if err = minioClient.FGetObjectWithContext(gContext, args[0], args[1], args[2], minio.GetObjectOptions{}); err != nil {
return err
}
log.Printf("Successfully downloaded %s into %q\n", args[1], args[2])
return nil
},
}
func init() {
sosCmd.AddCommand(downloadCmd)
}