From d8fdb8edb00733761e1e2b1087b15309dfc20d56 Mon Sep 17 00:00:00 2001 From: finn Date: Sat, 26 Mar 2022 01:23:26 -0700 Subject: [PATCH] add table output to preview subcommand --- cmd/signaldctl/cmd/group/preview/preview.go | 26 ++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/signaldctl/cmd/group/preview/preview.go b/cmd/signaldctl/cmd/group/preview/preview.go index 43cf888..4f51e77 100644 --- a/cmd/signaldctl/cmd/group/preview/preview.go +++ b/cmd/signaldctl/cmd/group/preview/preview.go @@ -22,7 +22,9 @@ import ( "os" "strings" + "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" @@ -68,8 +70,30 @@ var ( } switch common.OutputFormat { - case common.OutputFormatJSON, common.OutputFormatDefault: + case common.OutputFormatJSON: return json.NewEncoder(os.Stdout).Encode(info) + case common.OutputFormatYAML: + return yaml.NewEncoder(os.Stdout).Encode(info) + case common.OutputFormatDefault, common.OutputFormatTable: + t := table.NewWriter() + t.SetOutputMirror(os.Stdout) + + joinApproval := "unknown" + switch info.AddFromInviteLink { + case 3: + joinApproval = "yes" + case 1: + joinApproval = "no" + } + + t.AppendRows([]table.Row{ + table.Row{"Title", info.Title}, + table.Row{"Group ID", info.GroupID}, + table.Row{"Member Count", info.MemberCount}, + table.Row{"Membership Approval", joinApproval}, + }) + common.StylizeTable(t) + t.Render() } return nil