-
Notifications
You must be signed in to change notification settings - Fork 67
/
export_cmd.go
46 lines (38 loc) · 1.18 KB
/
export_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"
"fmt"
"strings"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/spf13/cobra"
)
var (
exportResourceID string
exportResourceFile string
)
var exportCmd = &cobra.Command{
GroupID: cmdGroupResources.ID,
Use: fmt.Sprintf("export %s", strings.Join(parameters.ValidResources, "|")),
Long: "Export a resource from your Tracetest server",
Short: "Export resource",
PreRun: setupCommand(),
Run: WithResultHandler(func(_ *cobra.Command, args []string) (string, error) {
resourceType := args[0]
ctx := context.Background()
resourceActions, err := resourceRegistry.Get(resourceType)
if err != nil {
return "", err
}
err = resourceActions.Export(ctx, exportResourceID, exportResourceFile)
if err != nil {
return "", err
}
return fmt.Sprintf("✔ Definition exported successfully for resource type: %s", resourceType), nil
}),
PostRun: teardownCommand,
}
func init() {
exportCmd.Flags().StringVar(&exportResourceID, "id", "", "id of the resource to export")
exportCmd.Flags().StringVarP(&exportResourceFile, "file", "f", "resource.yaml", "file path with name where to export the resource")
rootCmd.AddCommand(exportCmd)
}