提交 b5f72ee5 编写于 作者: K kezhenxu94 提交者: wu-sheng

Support list single service by service name (#12)

上级 7fdc8fb1
......@@ -29,10 +29,12 @@ import (
)
var ListCommand = cli.Command{
Name: "list",
ShortName: "ls",
Usage: "List all available services",
Flags: flags.DurationFlags,
Name: "list",
ShortName: "ls",
Usage: "List services",
ArgsUsage: "<service name>",
Description: "list all services if no <service name> is given, otherwise, only list the given service",
Flags: flags.DurationFlags,
Before: interceptor.BeforeChain([]cli.BeforeFunc{
interceptor.DurationInterceptor,
}),
......@@ -40,11 +42,19 @@ var ListCommand = cli.Command{
end := ctx.String("end")
start := ctx.String("start")
step := ctx.Generic("step")
services := client.Services(ctx, schema.Duration{
Start: start,
End: end,
Step: step.(*model.StepEnumValue).Selected,
})
var services []schema.Service
if args := ctx.Args(); len(args) == 0 {
services = client.Services(ctx, schema.Duration{
Start: start,
End: end,
Step: step.(*model.StepEnumValue).Selected,
})
} else {
service, _ := client.SearchService(ctx, args.First())
services = []schema.Service{service}
}
return display.Display(ctx, services)
},
......
......@@ -86,8 +86,8 @@ func SearchService(cliCtx *cli.Context, serviceCode string) (service schema.Serv
var response map[string]schema.Service
request := graphql.NewRequest(`
query searchService($serviceCode: String!) {
service: searchService(serviceCode: $serviceCode) {
id name
service: searchService(serviceCode: $serviceCode) {
id name
}
}
`)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册