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"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rmCmd = &cobra.Command{
|
|
|
|
Use: "rm PATH",
|
|
|
|
Short: "Remove files and directories from dbfs.",
|
|
|
|
Long: `Remove files and directories from dbfs.`,
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
PreRunE: root.MustWorkspaceClient,
|
|
|
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
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-06-05 23:21:47 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var recursive bool
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rmCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Recursively delete a non-empty directory.")
|
|
|
|
fsCmd.AddCommand(rmCmd)
|
|
|
|
}
|