mirror of https://github.com/mitchell/selfpass.git
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"gopkg.in/AlecAivazis/survey.v1"
|
|
)
|
|
|
|
func makeDelete(initClient credentialsClientInit) *cobra.Command {
|
|
flags := credentialFlagSet{}.withHostFlag()
|
|
|
|
deleteCmd := &cobra.Command{
|
|
Use: "delete",
|
|
Short: "Delete a credential using the given ID",
|
|
Long: `Delete a credential using the given ID, permanently. THERE IS NO UNDOING THIS ACTION.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
|
|
defer cancel()
|
|
|
|
client := initClient(ctx)
|
|
|
|
cred := selectCredential(client, flags.sourceHost)
|
|
|
|
fmt.Println(cred)
|
|
|
|
var confirmed bool
|
|
prompt := &survey.Confirm{Message: "Are you sure you want to permanently delete this credential?"}
|
|
check(survey.AskOne(prompt, &confirmed, nil))
|
|
|
|
if confirmed {
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*25)
|
|
defer cancel()
|
|
|
|
check(initClient(ctx).Delete(ctx, cred.ID))
|
|
}
|
|
},
|
|
}
|
|
|
|
flags.register(deleteCmd)
|
|
|
|
return deleteCmd
|
|
}
|