Improve error handling in signaldctl

This commit is contained in:
Finn 2021-02-28 13:25:34 -08:00
parent 60778761c2
commit 976744198e
10 changed files with 24 additions and 5 deletions

View file

@ -35,11 +35,12 @@ var (
ListDeviceCmd = &cobra.Command{
Use: "list",
Short: "list all devices linked to the account",
PreRun: func(_ *cobra.Command, args []string) {
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")
}
},

View file

@ -17,6 +17,7 @@ package remove
import (
"log"
"strconv"
"github.com/spf13/cobra"
@ -32,13 +33,23 @@ var (
RemoveDeviceCmd = &cobra.Command{
Use: "remove <device id>",
Short: "remove a linked device",
PreRun: func(_ *cobra.Command, args []string) {
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 device ID")
}
d, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
log.Fatal("unable to parse number: " + args[0])
}
device = d
},
Run: func(_ *cobra.Command, args []string) {
go common.Signald.Listen(nil)
@ -56,6 +67,5 @@ var (
func init() {
RemoveDeviceCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use")
RemoveDeviceCmd.Flags().Int64VarP(&device, "device", "d", 0, "device ID to remove")
common.Must(RemoveDeviceCmd.MarkFlagRequired("device"))
}

View file

@ -39,6 +39,7 @@ var (
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) == 0 {

View file

@ -42,6 +42,7 @@ var (
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) == 0 {

View file

@ -39,6 +39,7 @@ var (
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) == 0 {

View file

@ -34,11 +34,12 @@ var (
ListGroupCmd = &cobra.Command{
Use: "list",
Short: "return a list of Signal groups",
PreRun: func(_ *cobra.Command, _ []string) {
PreRun: func(cmd *cobra.Command, _ []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")
}
},

View file

@ -39,6 +39,7 @@ var (
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) == 0 {

View file

@ -47,6 +47,7 @@ var (
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) != 3 {

View file

@ -37,6 +37,7 @@ var (
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) < 2 {

View file

@ -35,13 +35,14 @@ var (
account string
SendMessageCmd = &cobra.Command{
Use: "send <group id> | <phone number> <message>",
Use: "send <group id | phone number> <message>",
Short: "send a message",
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) < 2 {