github.com/adowair/kvdb@v0.0.0-20231101174258-ceca93b03596/cmd/del.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/adowair/kvdb/kv"
     7  	"github.com/spf13/cobra"
     8  )
     9  
    10  // delCmd represents the del command
    11  var delCmd = &cobra.Command{
    12  	Use:   "del",
    13  	Short: "Delete a key",
    14  	Long: `Delete a key from the database. This removes the corresponding files
    15  from the underlying filesystem.`,
    16  	Args: cobra.ExactArgs(1),
    17  	RunE: func(cmd *cobra.Command, args []string) error {
    18  		key := args[0]
    19  		if err := kv.Delete(key); err != nil {
    20  			return err
    21  		}
    22  
    23  		fmt.Printf("Deleted %s\n", key)
    24  		return nil
    25  	},
    26  }
    27  
    28  func init() {
    29  	rootCmd.AddCommand(delCmd)
    30  
    31  	// Here you will define your flags and configuration settings.
    32  
    33  	// Cobra supports Persistent Flags which will work for this command
    34  	// and all subcommands, e.g.:
    35  	// delCmd.PersistentFlags().String("foo", "", "A help for foo")
    36  
    37  	// Cobra supports local flags which will only run when this command
    38  	// is called directly, e.g.:
    39  	// delCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
    40  }