diff --git a/cmd/signaldctl/cmd/account/delete/delete-account.go b/cmd/signaldctl/cmd/account/delete/delete-account.go new file mode 100644 index 0000000..1249d88 --- /dev/null +++ b/cmd/signaldctl/cmd/account/delete/delete-account.go @@ -0,0 +1,53 @@ +// Copyright © 2021 Finn Herzfeld +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +package delete + +import ( + "log" + + "github.com/spf13/cobra" + + "gitlab.com/signald/signald-go/cmd/signaldctl/common" + "gitlab.com/signald/signald-go/signald/client-protocol/v1" +) + +var ( + server bool + + DeleteAccountCmd = &cobra.Command{ + Use: "delete [phone number]", + Short: "delete an account from the local signald instance, and optionally from the server as well", + PreRun: func(cmd *cobra.Command, args []string) { + if len(args) != 1 { + common.Must(cmd.Help()) + log.Fatal("must specify phone number") + } + }, + Run: func(_ *cobra.Command, args []string) { + go common.Signald.Listen(nil) + req := v1.DeleteAccountRequest{Account: args[0]} + err := req.Submit(common.Signald) + if err != nil { + log.Fatal("error from signald: ", err) + } + log.Println("account deleted") + }, + } +) + +func init() { + DeleteAccountCmd.Flags().BoolVar(&server, "server", false, "delete the account from the server as well") +} diff --git a/cmd/signaldctl/cmd/account/root.go b/cmd/signaldctl/cmd/account/root.go index 95a77a6..adf9cc1 100644 --- a/cmd/signaldctl/cmd/account/root.go +++ b/cmd/signaldctl/cmd/account/root.go @@ -18,6 +18,7 @@ package account import ( "github.com/spf13/cobra" + "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/delete" "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/link" "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/list" "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/register" @@ -30,6 +31,7 @@ var AccountCmd = &cobra.Command{ } func init() { + AccountCmd.AddCommand(delete.DeleteAccountCmd) AccountCmd.AddCommand(link.LinkAccountCmd) AccountCmd.AddCommand(list.ListAccountCmd) AccountCmd.AddCommand(register.RegisterAccountCmd)