From ec3d46fcf36bb1fb27246d1305b6c5a03e80bb60 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Thu, 26 Aug 2021 21:10:02 +0000 Subject: [PATCH] Add account set-profile command --- cmd/signaldctl/cmd/account/root.go | 2 + .../cmd/account/setprofile/set-profile.go | 64 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 cmd/signaldctl/cmd/account/setprofile/set-profile.go diff --git a/cmd/signaldctl/cmd/account/root.go b/cmd/signaldctl/cmd/account/root.go index adf9cc1..ac812c0 100644 --- a/cmd/signaldctl/cmd/account/root.go +++ b/cmd/signaldctl/cmd/account/root.go @@ -22,6 +22,7 @@ import ( "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" + "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/setprofile" "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/verify" ) @@ -36,4 +37,5 @@ func init() { AccountCmd.AddCommand(list.ListAccountCmd) AccountCmd.AddCommand(register.RegisterAccountCmd) AccountCmd.AddCommand(verify.VerifyAccountCmd) + AccountCmd.AddCommand(setprofile.SetProfileCmd) } diff --git a/cmd/signaldctl/cmd/account/setprofile/set-profile.go b/cmd/signaldctl/cmd/account/setprofile/set-profile.go new file mode 100644 index 0000000..a1c646a --- /dev/null +++ b/cmd/signaldctl/cmd/account/setprofile/set-profile.go @@ -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 . + +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") +}