-
Notifications
You must be signed in to change notification settings - Fork 67
/
configure_cmd.go
48 lines (39 loc) 路 1.43 KB
/
configure_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
package cmd
import (
"context"
"github.com/kubeshop/tracetest/cli/actions"
"github.com/kubeshop/tracetest/cli/parameters"
"github.com/kubeshop/tracetest/cli/utils"
"github.com/spf13/cobra"
)
var configParams = ¶meters.ConfigureParams{}
var configureCmd = &cobra.Command{
GroupID: cmdGroupConfig.ID,
Use: "configure",
Short: "Configure your tracetest CLI",
Long: "Configure your tracetest CLI",
PreRun: setupLogger,
Run: WithResultHandler(WithParamsHandler(configParams)(func(cmd *cobra.Command, _ []string) (string, error) {
ctx := context.Background()
client := utils.GetAPIClient(cliConfig)
action := actions.NewConfigureAction(cliConfig, cliLogger, client)
actionConfig := actions.ConfigureConfig{
Global: configParams.Global,
SetValues: actions.ConfigureConfigSetValues{},
}
if flagProvided(cmd, "endpoint") {
actionConfig.SetValues.Endpoint = &configParams.Endpoint
}
err := action.Run(ctx, actionConfig)
return "", err
})),
PostRun: teardownCommand,
}
func flagProvided(cmd *cobra.Command, name string) bool {
return cmd.Flags().Lookup(name).Changed
}
func init() {
configureCmd.PersistentFlags().BoolVarP(&configParams.Global, "global", "g", false, "configuration will be saved in your home dir")
configureCmd.PersistentFlags().StringVarP(&configParams.Endpoint, "endpoint", "e", "", "set the value for the endpoint, so the CLI won't ask for this value")
rootCmd.AddCommand(configureCmd)
}