-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathstorage.go
99 lines (90 loc) · 3.29 KB
/
storage.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package cmd
import (
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/supabase/cli/internal/storage/client"
"github.com/supabase/cli/internal/storage/cp"
"github.com/supabase/cli/internal/storage/ls"
"github.com/supabase/cli/internal/storage/mv"
"github.com/supabase/cli/internal/storage/rm"
"github.com/supabase/cli/pkg/storage"
)
var (
storageCmd = &cobra.Command{
GroupID: groupManagementAPI,
Use: "storage",
Short: "Manage Supabase Storage objects",
}
recursive bool
lsCmd = &cobra.Command{
Use: "ls [path]",
Example: "ls ss:///bucket/docs",
Short: "List objects by path prefix",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
objectPath := client.STORAGE_SCHEME + ":///"
if len(args) > 0 {
objectPath = args[0]
}
return ls.Run(cmd.Context(), objectPath, recursive, afero.NewOsFs())
},
}
options storage.FileOptions
maxJobs uint
cpCmd = &cobra.Command{
Use: "cp <src> <dst>",
Example: `cp readme.md ss:///bucket/readme.md
cp -r docs ss:///bucket/docs
cp -r ss:///bucket/docs .
`,
Short: "Copy objects from src to dst path",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
opts := func(fo *storage.FileOptions) {
fo.CacheControl = options.CacheControl
fo.ContentType = options.ContentType
}
return cp.Run(cmd.Context(), args[0], args[1], recursive, maxJobs, afero.NewOsFs(), opts)
},
}
mvCmd = &cobra.Command{
Use: "mv <src> <dst>",
Short: "Move objects from src to dst path",
Example: "mv -r ss:///bucket/docs ss:///bucket/www/docs",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return mv.Run(cmd.Context(), args[0], args[1], recursive, afero.NewOsFs())
},
}
rmCmd = &cobra.Command{
Use: "rm <file> ...",
Short: "Remove objects by file path",
Example: `rm -r ss:///bucket/docs
rm ss:///bucket/docs/example.md ss:///bucket/readme.md
`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return rm.Run(cmd.Context(), args, recursive, afero.NewOsFs())
},
}
)
func init() {
storageFlags := storageCmd.PersistentFlags()
storageFlags.Bool("linked", true, "Connects to Storage API of the linked project.")
storageFlags.Bool("local", false, "Connects to Storage API of the local database.")
storageCmd.MarkFlagsMutuallyExclusive("linked", "local")
lsCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Recursively list a directory.")
storageCmd.AddCommand(lsCmd)
cpFlags := cpCmd.Flags()
cpFlags.BoolVarP(&recursive, "recursive", "r", false, "Recursively copy a directory.")
cpFlags.StringVar(&options.CacheControl, "cache-control", "max-age=3600", "Custom Cache-Control header for HTTP upload.")
cpFlags.StringVar(&options.ContentType, "content-type", "", "Custom Content-Type header for HTTP upload.")
cpFlags.Lookup("content-type").DefValue = "auto-detect"
cpFlags.UintVarP(&maxJobs, "jobs", "j", 1, "Maximum number of parallel jobs.")
storageCmd.AddCommand(cpCmd)
rmCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Recursively remove a directory.")
storageCmd.AddCommand(rmCmd)
mvCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Recursively move a directory.")
storageCmd.AddCommand(mvCmd)
rootCmd.AddCommand(storageCmd)
}