2023-06-05 23:21:47 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/databricks/cli/cmd/root"
|
2023-06-16 15:09:08 +00:00
|
|
|
"github.com/databricks/cli/libs/filer"
|
2023-06-05 23:21:47 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
func newRmCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "rm PATH",
|
2024-02-20 16:14:37 +00:00
|
|
|
Short: "Remove files and directories.",
|
|
|
|
Long: `Remove files and directories from DBFS and UC Volumes.`,
|
2024-03-12 14:12:34 +00:00
|
|
|
Args: root.ExactArgs(1),
|
2023-07-27 10:03:08 +00:00
|
|
|
PreRunE: root.MustWorkspaceClient,
|
|
|
|
}
|
2023-06-05 23:21:47 +00:00
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
var recursive bool
|
|
|
|
cmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Recursively delete a non-empty directory.")
|
|
|
|
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
2023-06-05 23:21:47 +00:00
|
|
|
ctx := cmd.Context()
|
|
|
|
|
2023-06-16 15:09:08 +00:00
|
|
|
f, path, err := filerForPath(ctx, args[0])
|
2023-06-05 23:21:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-06-16 15:09:08 +00:00
|
|
|
if recursive {
|
|
|
|
return f.Delete(ctx, path, filer.DeleteRecursively)
|
|
|
|
}
|
|
|
|
return f.Delete(ctx, path)
|
2023-07-27 10:03:08 +00:00
|
|
|
}
|
2023-06-05 23:21:47 +00:00
|
|
|
|
2023-07-27 10:03:08 +00:00
|
|
|
return cmd
|
2023-06-05 23:21:47 +00:00
|
|
|
}
|