|
| 1 | +// Licensed to Apache Software Foundation (ASF) under one or more contributor |
| 2 | +// license agreements. See the NOTICE file distributed with |
| 3 | +// this work for additional information regarding copyright |
| 4 | +// ownership. Apache Software Foundation (ASF) licenses this file to you under |
| 5 | +// the Apache License, Version 2.0 (the "License"); you may |
| 6 | +// not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package alarm |
| 19 | + |
| 20 | +import ( |
| 21 | + "github.com/urfave/cli/v2" |
| 22 | + |
| 23 | + "github.com/apache/skywalking-cli/internal/commands/interceptor" |
| 24 | + "github.com/apache/skywalking-cli/internal/flags" |
| 25 | + "github.com/apache/skywalking-cli/internal/model" |
| 26 | + "github.com/apache/skywalking-cli/pkg/display" |
| 27 | + "github.com/apache/skywalking-cli/pkg/display/displayable" |
| 28 | + "github.com/apache/skywalking-cli/pkg/graphql/alarm" |
| 29 | + |
| 30 | + api "skywalking.apache.org/repo/goapi/query" |
| 31 | +) |
| 32 | + |
| 33 | +var autocompleteKeysCommand = &cli.Command{ |
| 34 | + Name: "autocomplete-keys", |
| 35 | + Aliases: []string{"ks"}, |
| 36 | + Usage: "Query autocomplete Keys", |
| 37 | + UsageText: `Query autocomplete keys |
| 38 | +
|
| 39 | +Examples: |
| 40 | +1. Query autocomplete keys: |
| 41 | +$ swctl alarm autocomplete-keys |
| 42 | +`, |
| 43 | + Flags: flags.Flags( |
| 44 | + flags.DurationFlags, |
| 45 | + ), |
| 46 | + Before: interceptor.BeforeChain( |
| 47 | + interceptor.DurationInterceptor, |
| 48 | + ), |
| 49 | + Action: func(ctx *cli.Context) error { |
| 50 | + start := ctx.String("start") |
| 51 | + end := ctx.String("end") |
| 52 | + step := ctx.Generic("step") |
| 53 | + |
| 54 | + duration := api.Duration{ |
| 55 | + Start: start, |
| 56 | + End: end, |
| 57 | + Step: step.(*model.StepEnumValue).Selected, |
| 58 | + } |
| 59 | + |
| 60 | + autocompleteKeys, err := alarm.TagAutocompleteKeys(ctx, duration) |
| 61 | + if err != nil { |
| 62 | + return err |
| 63 | + } |
| 64 | + |
| 65 | + return display.Display(ctx, &displayable.Displayable{Data: autocompleteKeys, Condition: duration}) |
| 66 | + }, |
| 67 | +} |
0 commit comments