diff --git a/cmd/add.go b/cmd/add.go index ab5ee133..9a88f546 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -10,7 +10,7 @@ import ( var ( addCmd = &cobra.Command{ Use: "add url", - Short: "Bookmark URL with comma-separated tags.", + Short: "Bookmark the specified URL.", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { // Read flag and arguments diff --git a/cmd/delete.go b/cmd/delete.go index 547d00f9..f71b48b1 100644 --- a/cmd/delete.go +++ b/cmd/delete.go @@ -11,11 +11,15 @@ var ( 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) and hyphenated range (e.g. 100-200). " + "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 { + if len(args) == 0 && !skipConfirmation { confirmDelete := "" fmt.Print("Remove ALL bookmarks? (y/n): ") fmt.Scanln(&confirmDelete) @@ -33,17 +37,21 @@ var ( os.Exit(1) } + if len(oldIndices) == 0 { + fmt.Println("No bookmarks deleted") + return + } + fmt.Println("Bookmarks has been deleted") - if len(oldIndices) > 0 { - for i, oldIndex := range oldIndices { - newIndex := newIndices[i] - fmt.Printf("Index %d moved to %d\n", oldIndex, newIndex) - } + for i, oldIndex := range oldIndices { + newIndex := newIndices[i] + fmt.Printf("Index %d moved to %d\n", oldIndex, newIndex) } }, } ) func init() { + deleteCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt and delete ALL bookmarks") rootCmd.AddCommand(deleteCmd) }