Add listAccounts

This commit is contained in:
Finn Herzfeld 2018-10-09 00:26:08 -07:00
parent 529dc8c03e
commit 352c423dd4
2 changed files with 69 additions and 3 deletions

View file

@ -0,0 +1,55 @@
// Copyright © 2018 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 cmd
import (
"fmt"
"math/rand"
"github.com/spf13/cobra"
"git.callpipe.com/finn/signald-go/signald"
)
// listAccountsCmd represents the listAccounts command
var listAccountsCmd = &cobra.Command{
Use: "listAccounts",
Short: "list of all the accounts registered to this signald instance.",
Long: `Prints a list of all users to stdout.`,
Run: func(cmd *cobra.Command, args []string) {
requestID := fmt.Sprint("signald-cli-", rand.Intn(1000))
s.SendRequest(signald.Request{
Type: "list_accounts",
ID: requestID,
})
c := make(chan signald.Response)
go s.Listen(c)
for {
message := <-c
if message.ID == requestID {
for _, account := range message.Data.Accounts {
fmt.Println(account.Username)
}
break
}
}
},
}
func init() {
RootCmd.AddCommand(listAccountsCmd)
}

View file

@ -10,6 +10,7 @@ type Response struct {
// ResponseData is where most of the data in the response is stored.
type ResponseData struct {
Groups []Group
Accounts []Account
URI string
Message string
}
@ -21,3 +22,13 @@ type Group struct {
Name string
AvatarID int
}
// Account represents a user account registered to signald
type Account struct {
Username string
DeviceID int
Filename string
Registered bool
HasKeys bool `json:"has_keys"`
Subscribed bool
}