github.com/GGP1/kure@v0.8.4/commands/2fa/rm/rm.go (about) 1 package rm 2 3 import ( 4 "fmt" 5 "io" 6 "strings" 7 8 "github.com/GGP1/kure/auth" 9 cmdutil "github.com/GGP1/kure/commands" 10 "github.com/GGP1/kure/db/totp" 11 "github.com/GGP1/kure/terminal" 12 13 "github.com/spf13/cobra" 14 bolt "go.etcd.io/bbolt" 15 ) 16 17 const example = ` 18 kure 2fa rm Sample` 19 20 // NewCmd returns the a new command. 21 func NewCmd(db *bolt.DB, r io.Reader) *cobra.Command { 22 return &cobra.Command{ 23 Use: "rm <name>", 24 Short: "Remove a two-factor authentication code from an entry", 25 Example: example, 26 Args: cmdutil.MustExist(db, cmdutil.TOTP), 27 PreRunE: auth.Login(db), 28 RunE: runRm(db, r), 29 } 30 } 31 32 func runRm(db *bolt.DB, r io.Reader) cmdutil.RunEFunc { 33 return func(cmd *cobra.Command, args []string) error { 34 name := strings.Join(args, " ") 35 name = cmdutil.NormalizeName(name) 36 37 if !terminal.Confirm(r, "Are you sure you want to proceed?") { 38 return nil 39 } 40 41 if err := totp.Remove(db, name); err != nil { 42 return err 43 } 44 45 fmt.Printf("\n%q TOTP removed\n", name) 46 return nil 47 } 48 }