Ai
1 Star 0 Fork 0

ryancartoon/sensu-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
interactive.go 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
package filter
import (
"strings"
"github.com/AlecAivazis/survey"
"github.com/sensu/sensu-go/cli/commands/helpers"
"github.com/sensu/sensu-go/types"
"github.com/spf13/pflag"
)
type filterOpts struct {
Action string `survey:"action"`
Name string `survey:"name"`
Namespace string `survey:"namespace"`
Expressions string `survey:"expressions"`
RuntimeAssets string `survey:"runtimeAssets"`
}
func newFilterOpts() *filterOpts {
return &filterOpts{}
}
func (opts *filterOpts) administerQuestionnaire(editing bool) error {
var qs = []*survey.Question{}
if !editing {
qs = append(qs, []*survey.Question{
{
Name: "name",
Prompt: &survey.Input{
Message: "Filter Name:",
Default: opts.Name,
},
Validate: survey.Required,
},
{
Name: "namespace",
Prompt: &survey.Input{
Message: "Namespace:",
Default: opts.Namespace,
},
Validate: survey.Required,
},
}...)
}
qs = append(qs, []*survey.Question{
{
Name: "action",
Prompt: &survey.Select{
Message: "Action:",
Options: types.EventFilterAllActions,
Default: types.EventFilterAllActions[0],
},
Validate: survey.Required,
},
{
Name: "expressions",
Prompt: &survey.Input{
Message: "Expressions (comma separated list):",
Default: opts.Expressions,
},
Validate: survey.Required,
},
{
Name: "runtimeAssets",
Prompt: &survey.Input{
Message: "Runtime Assets",
Default: "",
},
},
}...)
return survey.Ask(qs, opts)
}
func (opts *filterOpts) Copy(filter *types.EventFilter) {
filter.Action = opts.Action
filter.Name = opts.Name
filter.Namespace = opts.Namespace
filter.Expressions = helpers.SafeSplitCSV(opts.Expressions)
filter.RuntimeAssets = helpers.SafeSplitCSV(opts.RuntimeAssets)
}
func (opts *filterOpts) withFilter(filter *types.EventFilter) {
opts.Name = filter.Name
opts.Namespace = filter.Namespace
opts.Action = filter.Action
opts.Expressions = strings.Join(filter.Expressions, ",")
opts.RuntimeAssets = strings.Join(filter.RuntimeAssets, ",")
}
func (opts *filterOpts) withFlags(flags *pflag.FlagSet) {
opts.Action, _ = flags.GetString("action")
opts.Expressions, _ = flags.GetString("expressions")
if namespace := helpers.GetChangedStringValueFlag("namespace", flags); namespace != "" {
opts.Namespace = namespace
}
}
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

搜索帮助