forked from erdos-one/r2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls.go
42 lines (35 loc) · 883 Bytes
/
ls.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
package cmd
import (
"log"
"github.com/boatkit-io/r2/pkg"
"github.com/spf13/cobra"
)
// lsCmd represents the ls command
var lsCmd = &cobra.Command{
Use: "ls",
Short: "List either all buckets or all objects in a bucket",
Run: func(cmd *cobra.Command, args []string) {
// Get profile client
profileName, err := cmd.Flags().GetString("profile")
if err != nil {
log.Fatal(err)
}
c := pkg.Client(getProfile(profileName))
if len(args) > 0 {
// If args passed to ls, list objects in each bucket passed
for _, bucketName := range args {
// Remove URI scheme if present
bucketName = pkg.RemoveR2URIPrefix(bucketName)
b := c.Bucket(bucketName)
b.PrintObjects()
}
} else {
// If no args passed to ls, list all buckets
c.PrintBuckets()
}
},
}
func init() {
// Add the ls command to the root command
rootCmd.AddCommand(lsCmd)
}