databricks-cli/cmd/fs/rm.go

39 lines
873 B
Go
Raw Normal View History

2023-06-05 01:07:19 +00:00
package fs
import (
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/filer"
"github.com/databricks/databricks-sdk-go/service/files"
"github.com/spf13/cobra"
)
var rmCmd = &cobra.Command{
Use: "rm <dir-name>",
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()
w := root.WorkspaceClient(ctx)
path, err := filer.ResolveDbfsPath(args[0])
if err != nil {
return err
}
return w.Dbfs.Delete(ctx, files.Delete{
Path: path,
Recursive: recursive,
})
},
}
var recursive bool
func init() {
rmCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "Allow deletion of non-empty directories.")
fsCmd.AddCommand(rmCmd)
}