diff --git a/cmd/signaldctl/cmd/account/verify/verify-account.go b/cmd/signaldctl/cmd/account/verify/verify-account.go index 151804a..6ad7038 100644 --- a/cmd/signaldctl/cmd/account/verify/verify-account.go +++ b/cmd/signaldctl/cmd/account/verify/verify-account.go @@ -16,13 +16,16 @@ package verify import ( + "encoding/json" + "fmt" "log" + "os" "github.com/spf13/cobra" + "gopkg.in/yaml.v2" "gitlab.com/signald/signald-go/cmd/signaldctl/common" - "gitlab.com/signald/signald-go/signald" - "gitlab.com/signald/signald-go/signald/client-protocol/v0" + v1 "gitlab.com/signald/signald-go/signald/client-protocol/v1" ) var ( @@ -36,23 +39,30 @@ var ( } }, Run: func(_ *cobra.Command, args []string) { - requestID := signald.GenerateID() - err := common.Signald.RawRequest(v0.LegacyRequest{ - Type: "verify", - ID: requestID, - Username: args[0], - Code: args[1], - }) + go common.Signald.Listen(nil) + req := v1.VerifyRequest{ + Account: args[0], + Code: args[1], + } + resp, err := req.Submit(common.Signald) if err != nil { log.Fatal("error sending request to signald: ", err) } - c := make(chan v0.LegacyResponse) - go common.Signald.Listen(c) - response := signald.GetLegacyResponse(c, requestID) - if response.Type == "verification_succeeded" { - log.Println("verification succeeded") - } else { - log.Fatalf("unexpected response from signald when requesting verification code: %+v", response) + switch common.OutputFormat { + case common.OutputFormatJSON: + err := json.NewEncoder(os.Stdout).Encode(resp) + if err != nil { + log.Fatal(err, "error encoding response to stdout") + } + case common.OutputFormatYAML: + err := yaml.NewEncoder(os.Stdout).Encode(resp) + if err != nil { + log.Fatal(err, "error encoding response to stdout") + } + case common.OutputFormatDefault: + fmt.Println("verification succeeded") + default: + log.Fatal("Unsupported output format") } }, }