Update commands and its description

This commit is contained in:
Radhi Fadlillah 2018-01-30 13:31:31 +07:00
parent ed95ef98ad
commit 1fe1b22821
2 changed files with 15 additions and 7 deletions

View file

@ -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

View file

@ -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)
}
}
},
}
)
func init() {
deleteCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt and delete ALL bookmarks")
rootCmd.AddCommand(deleteCmd)
}