mirror of
https://github.com/go-shiori/shiori.git
synced 2024-11-16 22:25:13 +08:00
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
deleteCmd = &cobra.Command{
|
|
Use: "delete [indices]",
|
|
Short: "Delete the saved bookmarks",
|
|
Long: "Delete bookmarks. " +
|
|
"When a record is deleted, the last record is moved to the removed index. " +
|
|
"Accepts space-separated list of indices (e.g. 5 6 23 4 110 45), hyphenated range (e.g. 100-200) or both (e.g. 1-3 7 9). " +
|
|
"If no arguments, all records will be deleted.",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
// Read flags
|
|
skipConfirmation, _ := cmd.Flags().GetBool("yes")
|
|
|
|
// If no arguments, confirm to user
|
|
if len(args) == 0 && !skipConfirmation {
|
|
confirmDelete := ""
|
|
fmt.Print("Remove ALL bookmarks? (y/n): ")
|
|
fmt.Scanln(&confirmDelete)
|
|
|
|
if confirmDelete != "y" {
|
|
fmt.Println("No bookmarks deleted")
|
|
return
|
|
}
|
|
}
|
|
|
|
// Delete bookmarks from database
|
|
err := DB.DeleteBookmarks(args...)
|
|
if err != nil {
|
|
cError.Println(err)
|
|
}
|
|
},
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
deleteCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt and delete ALL bookmarks")
|
|
rootCmd.AddCommand(deleteCmd)
|
|
}
|