Add account set-profile command

This commit is contained in:
Bohdan Horbeshko 2021-08-26 21:10:02 +00:00 committed by Finn
parent 1cdfd16f11
commit ec3d46fcf3
2 changed files with 66 additions and 0 deletions

View file

@ -22,6 +22,7 @@ import (
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/link" "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/list"
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/register" "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/register"
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/setprofile"
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/verify" "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/verify"
) )
@ -36,4 +37,5 @@ func init() {
AccountCmd.AddCommand(list.ListAccountCmd) AccountCmd.AddCommand(list.ListAccountCmd)
AccountCmd.AddCommand(register.RegisterAccountCmd) AccountCmd.AddCommand(register.RegisterAccountCmd)
AccountCmd.AddCommand(verify.VerifyAccountCmd) AccountCmd.AddCommand(verify.VerifyAccountCmd)
AccountCmd.AddCommand(setprofile.SetProfileCmd)
} }

View file

@ -0,0 +1,64 @@
// Copyright © 2021 The signald-go Contributors.
//
// 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 <http://www.gnu.org/licenses/>.
package setprofile
import (
"log"
"github.com/spf13/cobra"
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
"gitlab.com/signald/signald-go/signald/client-protocol/v1"
)
var (
account string
SetProfileCmd = &cobra.Command{
Use: "set-profile name",
Short: "updates the profile data with a new name",
PreRun: func(cmd *cobra.Command, args []string) {
if account == "" {
account = config.Config.DefaultAccount
}
if account == "" {
common.Must(cmd.Help())
log.Fatal("No account specified. Please specify with --account or set a default")
}
if len(args) != 1 {
common.Must(cmd.Help())
log.Fatal("must specify a name")
}
},
Run: func(_ *cobra.Command, args []string) {
go common.Signald.Listen(nil)
req := v1.SetProfile{
Account: account,
Name: args[0],
}
err := req.Submit(common.Signald)
if err != nil {
log.Fatal("error from signald: ", err)
}
log.Println("profile set")
},
}
)
func init() {
SetProfileCmd.Flags().StringVarP(&account, "account", "a", "", "the signald account to use")
}