代码拉取完成,页面将自动刷新
package clusterrolebinding
import (
"io"
"strconv"
"github.com/sensu/sensu-go/cli"
"github.com/sensu/sensu-go/cli/commands/helpers"
"github.com/sensu/sensu-go/cli/elements/table"
"github.com/sensu/sensu-go/types"
"github.com/spf13/cobra"
)
// ListCommand defines a command to list cluster role bindings
func ListCommand(cli *cli.SensuCli) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "list cluster role bindings",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
opts, err := helpers.ListOptionsFromFlags(cmd.Flags())
if err != nil {
return err
}
// Fetch role bindings from API
results, err := cli.Client.ListClusterRoleBindings(&opts)
if err != nil {
return err
}
// Print the results based on the user preferences
resources := []types.Resource{}
for i := range results {
resources = append(resources, &results[i])
}
return helpers.Print(cmd, cli.Config.Format(), printToTable, resources, results)
},
}
helpers.AddFormatFlag(cmd.Flags())
helpers.AddFieldSelectorFlag(cmd.Flags())
helpers.AddLabelSelectorFlag(cmd.Flags())
helpers.AddChunkSizeFlag(cmd.Flags())
return cmd
}
func printToTable(results interface{}, writer io.Writer) {
table := table.New([]*table.Column{
{
Title: "Name",
ColumnStyle: table.PrimaryTextStyle,
CellTransformer: func(data interface{}) string {
clusterRoleBinding, ok := data.(types.ClusterRoleBinding)
if !ok {
return cli.TypeError
}
return clusterRoleBinding.Name
},
},
{
Title: "Cluster Role",
CellTransformer: func(data interface{}) string {
clusterRoleBinding, ok := data.(types.ClusterRoleBinding)
if !ok {
return cli.TypeError
}
return clusterRoleBinding.RoleRef.Name
},
},
{
Title: "Subjects",
CellTransformer: func(data interface{}) string {
clusterRoleBinding, ok := data.(types.ClusterRoleBinding)
if !ok {
return cli.TypeError
}
return strconv.Itoa(len(clusterRoleBinding.Subjects))
},
},
})
table.Render(writer, results)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。