-
Notifications
You must be signed in to change notification settings - Fork 67
/
resource_select_cmd.go
63 lines (53 loc) 路 1.7 KB
/
resource_select_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cmd
import (
"context"
"fmt"
"strings"
"github.com/kubeshop/tracetest/cli/config"
"github.com/spf13/cobra"
)
type selectableFn func(ctx context.Context, cfg config.Config, flags config.ConfigFlags)
var (
selectParams = &selectParameters{}
selectCmd *cobra.Command
selectable = strings.Join([]string{"organization"}, "|")
selectableMap = map[string]selectableFn{
"organization": func(ctx context.Context, cfg config.Config, flags config.ConfigFlags) {
configurator.ShowOrganizationSelector(ctx, cfg, flags)
}}
)
func init() {
selectCmd = &cobra.Command{
GroupID: cmdGroupCloud.ID,
Use: "select " + selectable,
Short: "Select resources",
Long: "Select resources to your Tracetest CLI config",
PreRun: setupCommand(),
Run: WithResourceMiddleware(func(_ *cobra.Command, args []string) (string, error) {
resourceType := resourceParams.ResourceName
ctx := context.Background()
selectableFn, ok := selectableMap[resourceType]
if !ok {
return "", fmt.Errorf("resource type %s not selectable. Selectable resources are %s", resourceType, selectable)
}
flags := config.ConfigFlags{
OrganizationID: selectParams.organizationID,
EnvironmentID: selectParams.environmentID,
}
selectableFn(ctx, cliConfig, flags)
return "", nil
}),
PostRun: teardownCommand,
}
if isCloudEnabled {
selectCmd.Flags().StringVarP(&selectParams.organizationID, "organization", "", "", "organization id")
selectCmd.Flags().StringVarP(&selectParams.environmentID, "environment", "", "", "environment id")
rootCmd.AddCommand(selectCmd)
}
}
type selectParameters struct {
organizationID string
environmentID string
endpoint string
agentApiKey string
}