mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-04-25 14:09:15 -05:00
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package fs
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"codeberg.org/shroff/phylum/server/internal/command/common"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func setupDeleteCommand() *cobra.Command {
|
|
cmd := cobra.Command{
|
|
Use: "delete <path>",
|
|
Aliases: []string{"rm"},
|
|
Short: "Delete Resource",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
f := common.UserFileSystem(cmd)
|
|
pathOrUUID := args[0]
|
|
r, err := f.ResourceByPathWithRoot(pathOrUUID)
|
|
if err != nil {
|
|
fmt.Println("cannot remove '" + pathOrUUID + "': " + err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
if r.Dir() {
|
|
if recursive, err := cmd.Flags().GetBool("recursive"); err != nil || !recursive {
|
|
fmt.Println("cannot remove '" + pathOrUUID + "': Is a directory. Try again with '-r'")
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
hard, _ := cmd.Flags().GetBool("hard")
|
|
if hard {
|
|
err = f.DeleteForever(r)
|
|
} else {
|
|
_, err = f.Delete(r)
|
|
}
|
|
if err != nil {
|
|
fmt.Println("cannot remove '" + pathOrUUID + "': " + err.Error())
|
|
os.Exit(1)
|
|
}
|
|
},
|
|
}
|
|
cmd.Flags().BoolP("recursive", "r", false, "Recursive (required for directories)")
|
|
cmd.Flags().BoolP("hard", "x", false, "Permanently delete (do not send to trash)")
|
|
|
|
return &cmd
|
|
}
|