diff --git a/cmd/signaldctl/cmd/device/add/add-device.go b/cmd/signaldctl/cmd/device/add/add-device.go new file mode 100644 index 0000000..63d205b --- /dev/null +++ b/cmd/signaldctl/cmd/device/add/add-device.go @@ -0,0 +1,66 @@ +// Copyright © 2021 Finn Herzfeld +// +// 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 . + +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 ", + 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") +} diff --git a/cmd/signaldctl/cmd/device/list/list.go b/cmd/signaldctl/cmd/device/list/list.go index 6305eae..227829e 100644 --- a/cmd/signaldctl/cmd/device/list/list.go +++ b/cmd/signaldctl/cmd/device/list/list.go @@ -83,3 +83,7 @@ var ( }, } ) + +func init() { + ListDeviceCmd.Flags().StringVarP(&account, "account", "a", "", "local account to use") +}