signaldctl can now add linked devices

This commit is contained in:
Finn 2021-03-22 03:19:29 -07:00
parent 76e174bee6
commit 5172f3ae6f
2 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1,66 @@
// Copyright © 2021 Finn Herzfeld <finn@janky.solutions>
//
// 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 <http://www.gnu.org/licenses/>.
package add
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
uri string
RemoveDeviceCmd = &cobra.Command{
Use: "add <tsdevice uri>",
Short: "add a linked device",
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 a linking URI")
}
uri = args[1]
},
Run: func(_ *cobra.Command, args []string) {
go common.Signald.Listen(nil)
req := v1.AddLinkedDeviceRequest{
Account: account,
Uri: uri,
}
err := req.Submit(common.Signald)
if err != nil {
log.Fatal("error sending request to signald: ", err)
}
log.Println("successfully added device")
},
}
)
func init() {
RemoveDeviceCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use")
}

View file

@ -83,3 +83,7 @@ var (
},
}
)
func init() {
ListDeviceCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use")
}