clean up some UX and improve validation
This commit is contained in:
parent
4fb2cd3147
commit
f4487704cd
10 changed files with 56 additions and 68 deletions
|
@ -26,23 +26,23 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
phoneNumber string
|
||||
voice bool
|
||||
voice bool
|
||||
|
||||
RegisterAccountCmd = &cobra.Command{
|
||||
Use: "register",
|
||||
Use: "register [phone number]",
|
||||
Short: "begin the process of creating a new account",
|
||||
PreRun: func(_ *cobra.Command, _ []string) {
|
||||
if phoneNumber == "" {
|
||||
log.Fatal("--phone-number required")
|
||||
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, _ []string) {
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
requestID := signald.GenerateID()
|
||||
err := common.Signald.RawRequest(v0.LegacyRequest{
|
||||
Type: "register",
|
||||
ID: requestID,
|
||||
Username: phoneNumber,
|
||||
Username: args[0],
|
||||
Voice: voice,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -52,7 +52,7 @@ var (
|
|||
go common.Signald.Listen(c)
|
||||
response := signald.GetLegacyResponse(c, requestID)
|
||||
if response.Type == "verification_required" {
|
||||
log.Println("verification code requested. submit with: signaldctl account verify --phone-number", phoneNumber, "--code XXX-XXX")
|
||||
log.Println("verification code requested. submit with: signaldctl account verify", args[0], "<code>")
|
||||
} else {
|
||||
log.Fatalf("unexpected response from signald when requesting verification code: %+v", response)
|
||||
}
|
||||
|
@ -61,6 +61,5 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
RegisterAccountCmd.Flags().StringVarP(&phoneNumber, "number", "n", "", "phone number being registered")
|
||||
RegisterAccountCmd.Flags().BoolVarP(&voice, "voice", "V", false, "request verification code be sent via an automated voice call (code is sent via SMS by default)")
|
||||
}
|
||||
|
|
|
@ -26,27 +26,22 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
phoneNumber string
|
||||
code string
|
||||
|
||||
VerifyAccountCmd = &cobra.Command{
|
||||
Use: "verify",
|
||||
Use: "verify [phone number] [code]",
|
||||
Short: "verify an account and complete the registration process",
|
||||
PreRun: func(_ *cobra.Command, _ []string) {
|
||||
if phoneNumber == "" {
|
||||
log.Fatal("--phone-number required")
|
||||
}
|
||||
if code == "" {
|
||||
log.Fatal("--code required")
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("must specify phone number and code")
|
||||
}
|
||||
},
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
requestID := signald.GenerateID()
|
||||
err := common.Signald.RawRequest(v0.LegacyRequest{
|
||||
Type: "verify",
|
||||
ID: requestID,
|
||||
Username: phoneNumber,
|
||||
Code: code,
|
||||
Username: args[0],
|
||||
Code: args[1],
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal("error sending request to signald: ", err)
|
||||
|
@ -62,8 +57,3 @@ var (
|
|||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
VerifyAccountCmd.Flags().StringVarP(&phoneNumber, "phone-number", "n", "", "phone number being verified")
|
||||
VerifyAccountCmd.Flags().StringVarP(&code, "code", "c", "", "verification code to submit")
|
||||
}
|
||||
|
|
|
@ -21,15 +21,18 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/config"
|
||||
)
|
||||
|
||||
var (
|
||||
SetConfigCmd = &cobra.Command{
|
||||
Use: "set",
|
||||
Short: "send a message",
|
||||
PreRun: func(_ *cobra.Command, args []string) {
|
||||
Use: "set <key> <value>",
|
||||
Short: "send a message",
|
||||
Annotations: map[string]string{common.AnnotationNoSocketConnection: "true"},
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("unexpected number of arguments")
|
||||
}
|
||||
},
|
||||
|
|
|
@ -30,7 +30,7 @@ var (
|
|||
device int64
|
||||
|
||||
RemoveDeviceCmd = &cobra.Command{
|
||||
Use: "remove",
|
||||
Use: "remove <device id>",
|
||||
Short: "remove a linked device",
|
||||
PreRun: func(_ *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
|
|
|
@ -32,9 +32,9 @@ import (
|
|||
var (
|
||||
account string
|
||||
AcceptGroupInvitationCmd = &cobra.Command{
|
||||
Use: "accept",
|
||||
Use: "accept <group id> [<group id>...]",
|
||||
Short: "accept an invitation to join a group",
|
||||
PreRun: func(_ *cobra.Command, args []string) {
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ var (
|
|||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if len(args) == 0 {
|
||||
log.Fatal("at least one group ID required")
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("must specify at least one group id")
|
||||
}
|
||||
},
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
|
|
|
@ -32,9 +32,9 @@ import (
|
|||
var (
|
||||
account string
|
||||
ShowGroupCmd = &cobra.Command{
|
||||
Use: "show",
|
||||
Use: "show <group id> [<group id>]",
|
||||
Short: "show details about a group",
|
||||
PreRun: func(_ *cobra.Command, args []string) {
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ var (
|
|||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if len(args) == 0 {
|
||||
log.Fatal("at least one group ID required")
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("must specify at least one group id")
|
||||
}
|
||||
},
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
|
|
|
@ -41,7 +41,7 @@ var (
|
|||
ReactMessageCmd = &cobra.Command{
|
||||
Use: "react",
|
||||
Short: "react to a message",
|
||||
PreRun: func(_ *cobra.Command, args []string) {
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ var (
|
|||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if len(args) != 1 {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("must provide exactly one reaction")
|
||||
}
|
||||
},
|
||||
|
|
|
@ -30,9 +30,9 @@ var (
|
|||
account string
|
||||
|
||||
ReadMessageCmd = &cobra.Command{
|
||||
Use: "mark-read",
|
||||
Use: "mark-read <author> <timestamp>",
|
||||
Short: "mark a message as read",
|
||||
PreRun: func(_ *cobra.Command, args []string) {
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ var (
|
|||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if len(args) < 2 {
|
||||
log.Fatal("Usage: signaldctl message mark-read <author> <timestamp>")
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("must specify author and timestamp")
|
||||
}
|
||||
},
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
|
|
|
@ -33,38 +33,34 @@ import (
|
|||
|
||||
var (
|
||||
account string
|
||||
to string
|
||||
message string
|
||||
|
||||
SendMessageCmd = &cobra.Command{
|
||||
Use: "send",
|
||||
Use: "send <group id> | <phone number> <message>",
|
||||
Short: "send a message",
|
||||
PreRun: func(_ *cobra.Command, _ []string) {
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if account == "" {
|
||||
account = config.Config.DefaultAccount
|
||||
}
|
||||
if account == "" {
|
||||
log.Fatal("No account specified. Please specify with --account or set a default")
|
||||
}
|
||||
if to == "" {
|
||||
log.Fatal("--to required")
|
||||
}
|
||||
if message == "" {
|
||||
log.Fatal("--message required")
|
||||
if len(args) < 2 {
|
||||
common.Must(cmd.Help())
|
||||
log.Fatal("must specify both destination (either group id or phone number) and message")
|
||||
}
|
||||
},
|
||||
Run: func(_ *cobra.Command, _ []string) {
|
||||
Run: func(_ *cobra.Command, args []string) {
|
||||
go common.Signald.Listen(nil)
|
||||
|
||||
req := v1.SendRequest{
|
||||
Username: account,
|
||||
MessageBody: message,
|
||||
MessageBody: strings.Join(args[1:], " "),
|
||||
}
|
||||
|
||||
if strings.HasPrefix(to, "+") {
|
||||
req.RecipientAddress = &v1.JsonAddress{Number: to}
|
||||
if strings.HasPrefix(args[0], "+") {
|
||||
req.RecipientAddress = &v1.JsonAddress{Number: args[0]}
|
||||
} else {
|
||||
req.RecipientGroupID = to
|
||||
req.RecipientGroupID = args[0]
|
||||
}
|
||||
|
||||
resp, err := req.Submit(common.Signald)
|
||||
|
@ -124,6 +120,4 @@ var (
|
|||
|
||||
func init() {
|
||||
SendMessageCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use")
|
||||
SendMessageCmd.Flags().StringVarP(&to, "to", "t", "", "phone number or group ID to send the message to")
|
||||
SendMessageCmd.Flags().StringVarP(&message, "message", "m", "", "the body of the message to send")
|
||||
}
|
||||
|
|
|
@ -35,20 +35,18 @@ var versionCmd = &cobra.Command{
|
|||
Run: func(cmd *cobra.Command, args []string) {
|
||||
go common.Signald.Listen(nil)
|
||||
r := v1.VersionRequest{}
|
||||
response, err := r.Submit(common.Signald)
|
||||
signaldVersion, err := r.Submit(common.Signald)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
output := []v1.JsonVersionMessage{
|
||||
response,
|
||||
{
|
||||
Name: common.Name,
|
||||
Branch: common.Branch,
|
||||
Commit: common.Commit,
|
||||
Version: common.Version,
|
||||
},
|
||||
signaldctlVersion := v1.JsonVersionMessage{
|
||||
Name: common.Name,
|
||||
Branch: common.Branch,
|
||||
Commit: common.Commit,
|
||||
Version: common.Version,
|
||||
}
|
||||
output := []v1.JsonVersionMessage{signaldVersion, signaldctlVersion}
|
||||
switch common.OutputFormat {
|
||||
case common.OutputFormatJSON:
|
||||
err := json.NewEncoder(os.Stdout).Encode(output)
|
||||
|
@ -65,7 +63,7 @@ var versionCmd = &cobra.Command{
|
|||
t.SetOutputMirror(os.Stdout)
|
||||
t.AppendHeader(table.Row{"Name", "Version", "Branch", "Commit"})
|
||||
t.AppendRow(table.Row{common.Name, common.Version, common.Branch, common.Commit})
|
||||
t.AppendRow(table.Row{response.Name, response.Version, response.Branch, response.Commit})
|
||||
t.AppendRow(table.Row{signaldVersion.Name, signaldVersion.Version, signaldVersion.Branch, signaldVersion.Commit})
|
||||
if common.OutputFormat == common.OutputFormatCSV {
|
||||
t.RenderCSV()
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue