diff --git a/cmd/signaldctl/cmd/account/requestsync/main.go b/cmd/signaldctl/cmd/account/requestsync/main.go new file mode 100644 index 0000000..480a595 --- /dev/null +++ b/cmd/signaldctl/cmd/account/requestsync/main.go @@ -0,0 +1,36 @@ +package requestsync + +import ( + "log" + + "github.com/spf13/cobra" + "gitlab.com/signald/signald-go/cmd/signaldctl/common" + "gitlab.com/signald/signald-go/cmd/signaldctl/config" + v1 "gitlab.com/signald/signald-go/signald/client-protocol/v1" +) + +var ( + account string + RequestSyncCmd = &cobra.Command{ + Use: "request-sync", + Short: "Ask other devices on the account to send sync data. Must subscribe for result", + PreRun: func(cmd *cobra.Command, args []string) { + if account == "" { + account = config.Config.DefaultAccount + } + }, + Run: func(_ *cobra.Command, _ []string) { + go common.Signald.Listen(nil) + req := &v1.RequestSyncRequest{Account: account} + err := req.Submit(common.Signald) + if err != nil { + panic(err) + } + log.Println("sync requested. Must be subscribed to receive response") + }, + } +) + +func init() { + RequestSyncCmd.Flags().StringVarP(&account, "account", "a", "", "the signald account to use") +} diff --git a/cmd/signaldctl/cmd/account/root.go b/cmd/signaldctl/cmd/account/root.go index 2888868..aca722e 100644 --- a/cmd/signaldctl/cmd/account/root.go +++ b/cmd/signaldctl/cmd/account/root.go @@ -23,6 +23,7 @@ import ( "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/remoteconfig" + "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/requestsync" "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/setprofile" "gitlab.com/signald/signald-go/cmd/signaldctl/cmd/account/verify" ) @@ -37,7 +38,8 @@ func init() { AccountCmd.AddCommand(link.LinkAccountCmd) AccountCmd.AddCommand(list.ListAccountCmd) AccountCmd.AddCommand(register.RegisterAccountCmd) - AccountCmd.AddCommand(verify.VerifyAccountCmd) - AccountCmd.AddCommand(setprofile.SetProfileCmd) AccountCmd.AddCommand(remoteconfig.RemoteConfigCmd) + AccountCmd.AddCommand(requestsync.RequestSyncCmd) + AccountCmd.AddCommand(setprofile.SetProfileCmd) + AccountCmd.AddCommand(verify.VerifyAccountCmd) }