add table output to preview subcommand
This commit is contained in:
parent
ec276e5411
commit
d8fdb8edb0
1 changed files with 25 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue