-
Notifications
You must be signed in to change notification settings - Fork 67
/
apply_cmd.go
46 lines (37 loc) 路 1.13 KB
/
apply_cmd.go
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
package cmd
import (
"context"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/kubeshop/tracetest/cli/pkg/resourcemanager"
"github.com/spf13/cobra"
)
var applyParams = ¶meters.ApplyParams{}
var applyCmd = &cobra.Command{
GroupID: cmdGroupResources.ID,
Use: "apply " + resourceList(),
Short: "Apply resources",
Long: "Apply (create/update) resources to your Tracetest server",
PreRun: setupCommand(),
Run: WithResourceMiddleware(func(_ *cobra.Command, args []string) (string, error) {
resourceType := resourceParams.ResourceName
ctx := context.Background()
resourceClient, err := resources.Get(resourceType)
if err != nil {
return "", err
}
resultFormat, err := resourcemanager.Formats.GetWithFallback(output, "yaml")
if err != nil {
return "", err
}
result, err := resourceClient.Apply(ctx, applyParams.DefinitionFile, resultFormat)
if err != nil {
return "", err
}
return result, nil
}, applyParams),
PostRun: teardownCommand,
}
func init() {
applyCmd.Flags().StringVarP(&applyParams.DefinitionFile, "file", "f", "", "path to the definition file")
rootCmd.AddCommand(applyCmd)
}