Ai
1 Star 0 Fork 0

ryancartoon/sensu-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
info.go 1.65 KB
一键复制 编辑 原始数据 按行查看 历史
package hook
import (
"errors"
"fmt"
"io"
"strconv"
"github.com/sensu/sensu-go/cli"
"github.com/sensu/sensu-go/cli/commands/helpers"
"github.com/sensu/sensu-go/cli/elements/globals"
"github.com/sensu/sensu-go/cli/elements/list"
"github.com/sensu/sensu-go/types"
"github.com/spf13/cobra"
)
// InfoCommand defines new hook info command
func InfoCommand(cli *cli.SensuCli) *cobra.Command {
cmd := &cobra.Command{
Use: "info [ID]",
Short: "show detailed hook information",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
_ = cmd.Help()
return errors.New("invalid argument(s) received")
}
// Fetch handlers from API
hookID := args[0]
r, err := cli.Client.FetchHook(hookID)
if err != nil {
return err
}
// Determine the format to use to output the data
flag := helpers.GetChangedStringValueFlag("format", cmd.Flags())
format := cli.Config.Format()
return helpers.PrintFormatted(flag, format, r, cmd.OutOrStdout(), printToList)
},
}
helpers.AddFormatFlag(cmd.Flags())
return cmd
}
func printToList(v interface{}, writer io.Writer) error {
r, ok := v.(*types.HookConfig)
if !ok {
return fmt.Errorf("%t is not a HookConfig", v)
}
cfg := &list.Config{
Title: r.Name,
Rows: []*list.Row{
{
Label: "Name",
Value: r.Name,
},
{
Label: "Command",
Value: r.Command,
},
{
Label: "Timeout",
Value: strconv.FormatInt(int64(r.Timeout), 10),
},
{
Label: "Stdin?",
Value: globals.BooleanStyleP(r.Stdin),
},
{
Label: "Namespace",
Value: r.Namespace,
},
},
}
return list.Print(writer, cfg)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ryancartoon/sensu-go.git
git@gitee.com:ryancartoon/sensu-go.git
ryancartoon
sensu-go
sensu-go
v5.10.1

搜索帮助