diff --git a/cmd/mkdir.go b/cmd/mkdir.go new file mode 100644 index 0000000..9ccb7c9 --- /dev/null +++ b/cmd/mkdir.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "context" + "strings" + + "github.com/spf13/cobra" +) + +func init() { + cmd := &cobra.Command{ + Use: "mkdir rpath", + Short: "Create an empty remote directory.", + Example: strings.TrimSpace(` +# Create an empty directory +datasafed mkdir some/dir +`), + Args: cobra.ExactArgs(1), + Run: doMkdir, + } + rootCmd.AddCommand(cmd) +} + +func doMkdir(cmd *cobra.Command, args []string) { + err := globalStorage.Mkdir(context.Background(), args[0]) + exitIfError(err) +} diff --git a/pkg/storage/rclone/rclone.go b/pkg/storage/rclone/rclone.go index 0b1e21b..2a7afbe 100644 --- a/pkg/storage/rclone/rclone.go +++ b/pkg/storage/rclone/rclone.go @@ -114,6 +114,11 @@ func (s *rcloneStorage) Rmdir(ctx context.Context, rpath string) error { return s.f.Rmdir(ctx, rpath) } +func (s *rcloneStorage) Mkdir(ctx context.Context, rpath string) error { + rpath = normalizeRemotePath(rpath) + return s.f.Mkdir(ctx, rpath) +} + func (s *rcloneStorage) list(ctx context.Context, rpath string, opt *storage.ListOptions, callback func(item *operations.ListJSONItem) error) error { ljOpt := &operations.ListJSONOpt{} if opt != nil { diff --git a/pkg/storage/types.go b/pkg/storage/types.go index e7e6634..e2165b5 100644 --- a/pkg/storage/types.go +++ b/pkg/storage/types.go @@ -48,6 +48,9 @@ type Storage interface { // Rmdir removes the directory in the given path only if the directory is empty. Rmdir(ctx context.Context, rpath string) error + // Mkdir makes a directory. + Mkdir(ctx context.Context, rpath string) error + // List lists the contents of the given path. // The `rpath` parameter can also be a file, in this case the function // will return a list with a single entry.