get a specific group

This commit is contained in:
Finn 2021-02-02 01:18:37 -08:00
parent fe0484731f
commit 2b94a65ca0
8 changed files with 137 additions and 4 deletions

View file

@ -68,6 +68,7 @@ var (
if common.OutputFormat == common.OutputFormatCSV {
t.RenderCSV()
} else {
t.SetStyle(table.StyleLight)
t.Render()
}
case common.OutputFormatQR, common.OutputFormatDefault:

View file

@ -78,6 +78,7 @@ var (
if common.OutputFormat == common.OutputFormatCSV {
t.RenderCSV()
} else {
t.SetStyle(table.StyleLight)
t.Render()
}
default:

View file

@ -77,6 +77,7 @@ var (
if common.OutputFormat == common.OutputFormatCSV {
t.RenderCSV()
} else {
t.SetStyle(table.StyleLight)
t.Render()
}
default:
@ -88,5 +89,4 @@ var (
func init() {
ListGroupCmd.Flags().StringVarP(&account, "account", "a", "", "the signald account to use")
common.Must(ListGroupCmd.MarkFlagRequired("account"))
}

View file

@ -19,6 +19,7 @@ import (
"github.com/spf13/cobra"
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/list"
"gitlab.com/signald/signald-go/cmd/signaldctl/cmd/group/show"
)
var GroupCmd = &cobra.Command{
@ -28,4 +29,5 @@ var GroupCmd = &cobra.Command{
func init() {
GroupCmd.AddCommand(list.ListGroupCmd)
GroupCmd.AddCommand(show.ShowGroupCmd)
}

View file

@ -0,0 +1,127 @@
// 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 show
import (
"encoding/json"
"log"
"os"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"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
ShowGroupCmd = &cobra.Command{
Use: "show",
Short: "show details about a group",
PreRun: func(_ *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 len(args) == 0 {
log.Fatal("at least one group ID required")
}
},
Run: func(_ *cobra.Command, args []string) {
go common.Signald.Listen(nil)
responses := []v1.JsonGroupV2Info{}
for _, group := range args {
req := v1.GetGroupRequest{Account: account, GroupID: group}
resp, err := req.Submit(common.Signald)
if err != nil {
log.Fatal(err, "error communicating with signald")
}
responses = append(responses, resp)
}
switch common.OutputFormat {
case common.OutputFormatJSON:
err := json.NewEncoder(os.Stdout).Encode(responses)
if err != nil {
log.Fatal(err, "error encoding response to stdout")
}
case common.OutputFormatYAML:
err := yaml.NewEncoder(os.Stdout).Encode(responses)
if err != nil {
log.Fatal(err, "error encoding response to stdout")
}
case common.OutputFormatCSV, common.OutputFormatTable, common.OutputFormatDefault:
rowConfigAutoMerge := table.RowConfig{AutoMerge: true}
for _, resp := range responses {
t := table.NewWriter()
t.AppendHeader(table.Row{"Title", resp.Title}, rowConfigAutoMerge)
t.AppendRow(table.Row{"ID", resp.ID}, rowConfigAutoMerge)
t.AppendRow(table.Row{"Revision", resp.Revision}, rowConfigAutoMerge)
if resp.Timer > 0 {
t.AppendRow(table.Row{"Timer", resp.Timer}, rowConfigAutoMerge)
}
if resp.InviteLink != "" {
t.AppendRow(table.Row{"Invite Link", resp.InviteLink}, rowConfigAutoMerge)
}
for i, member := range resp.Members {
first := ""
if i == 0 {
first = "Members"
}
t.AppendRow(table.Row{first, member.UUID}, rowConfigAutoMerge)
}
for i, member := range resp.PendingMembers {
first := ""
if i == 0 {
first = "Pending Members"
}
t.AppendRow(table.Row{first, member.Number}, rowConfigAutoMerge)
}
for i, member := range resp.RequestingMembers {
first := ""
if i == 0 {
first = "Requesting Members"
}
t.AppendRow(table.Row{first, member.Number}, rowConfigAutoMerge)
}
t.SetOutputMirror(os.Stdout)
if common.OutputFormat == common.OutputFormatCSV {
t.RenderCSV()
} else {
t.SetStyle(table.StyleLight)
t.Render()
}
}
default:
log.Fatal("Unsupported output format")
}
},
}
)
func init() {
ShowGroupCmd.Flags().StringVarP(&account, "account", "a", "", "the signald account to use")
}

View file

@ -112,6 +112,7 @@ var (
if common.OutputFormat == common.OutputFormatCSV {
t.RenderCSV()
} else {
t.SetStyle(table.StyleLight)
t.Render()
}
default:

View file

@ -31,8 +31,7 @@ import (
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "print the signald version",
Long: `print the signald version`,
Short: "print the current signald and signaldctl version",
Run: func(cmd *cobra.Command, args []string) {
go common.Signald.Listen(nil)
r := v1.VersionRequest{}

View file

@ -25,7 +25,9 @@ import (
type Configuration struct {
// DefaultAccount will be used if --account is not provided
DefaultAccount string
SocketPath string
// SocketPath is the path to signald.sock
SocketPath string
}
var Path string