-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathotelrelationmapping_delete.go
More file actions
52 lines (44 loc) · 1.53 KB
/
otelrelationmapping_delete.go
File metadata and controls
52 lines (44 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package otelrelationmapping
import (
"fmt"
"github.com/spf13/cobra"
"github.com/stackvista/stackstate-cli/generated/stackstate_api"
"github.com/stackvista/stackstate-cli/internal/common"
"github.com/stackvista/stackstate-cli/internal/di"
)
type DeleteArgs struct {
Identifier string
}
func OtelRelationMappingDeleteCommand(deps *di.Deps) *cobra.Command {
args := &DeleteArgs{}
cmd := &cobra.Command{
Use: "delete",
Short: "Delete an OTel Relation Mapping by identifier (URN)",
Long: "Delete an OTel Relation Mapping by identifier (URN).",
Example: `# delete a relation mapping by identifier
sts otel-relation-mapping delete --identifier urn:stackpack:stackpack-name:shared:otel-relation-mapping:database`,
RunE: deps.CmdRunEWithApi(RunDeleteRelationMappingCommand(args)),
}
common.AddRequiredIdentifierFlagVar(cmd, &args.Identifier, "Identifier (URN) of the Relation Mapping to delete")
return cmd
}
func RunDeleteRelationMappingCommand(args *DeleteArgs) di.CmdWithApiFn {
return func(
cmd *cobra.Command,
cli *di.Deps,
api *stackstate_api.APIClient,
serverInfo *stackstate_api.ServerInfo,
) common.CLIError {
resp, err := api.OtelMappingApi.DeleteOtelRelationMapping(cli.Context, args.Identifier).Execute()
if err != nil {
return common.NewResponseError(err, resp)
}
result := map[string]interface{}{"deleted_identifier": args.Identifier}
if cli.IsJson() {
cli.Printer.PrintJson(result)
} else {
cli.Printer.Success(fmt.Sprintf("OTel Relation Mapping deleted: %s", args.Identifier))
}
return nil
}
}