Skip to content

Commit

Permalink
fix(cli): adding skip of version mismatch for the server install cmd (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Jun 5, 2023
1 parent f45bc54 commit f4ce24a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions cli/cmd/config.go
Expand Up @@ -26,7 +26,8 @@ var (
)

type setupConfig struct {
shouldValidateConfig bool
shouldValidateConfig bool
shouldValidateVersionMismatch bool
}

type setupOption func(*setupConfig)
Expand All @@ -37,9 +38,16 @@ func SkipConfigValidation() setupOption {
}
}

func SkipVersionMismatchCheck() setupOption {
return func(sc *setupConfig) {
sc.shouldValidateVersionMismatch = false
}
}

func setupCommand(options ...setupOption) func(cmd *cobra.Command, args []string) {
config := setupConfig{
shouldValidateConfig: true,
shouldValidateConfig: true,
shouldValidateVersionMismatch: true,
}
for _, option := range options {
option(&config)
Expand Down Expand Up @@ -109,6 +117,10 @@ func setupCommand(options ...setupOption) func(cmd *cobra.Command, args []string
validateConfig(cmd, args)
}

if config.shouldValidateVersionMismatch {
validateVersionMismatch()
}

analytics.Init(cliConfig)
}
}
Expand Down Expand Up @@ -202,7 +214,9 @@ func setupVersion() {

action := actions.NewGetServerVersionAction(options...)
versionText, isVersionMatch = action.GetVersion(ctx)
}

func validateVersionMismatch() {
if !isVersionMatch && os.Getenv("TRACETEST_DEV") == "" {
fmt.Fprintf(os.Stderr, versionText+`
✖️ Error: Version Mismatch
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/server_cmd.go
Expand Up @@ -9,7 +9,7 @@ var serverCmd = &cobra.Command{
Use: "server",
Short: "Manage your tracetest server",
Long: "Manage your tracetest server",
PreRun: setupCommand(),
PreRun: setupCommand(SkipVersionMismatchCheck()),
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/server_install_cmd.go
Expand Up @@ -18,7 +18,7 @@ var serverInstallCmd = &cobra.Command{
Use: "install",
Short: "Install a new Tracetest server",
Long: "Install a new Tracetest server",
PreRun: setupCommand(SkipConfigValidation()),
PreRun: setupCommand(SkipConfigValidation(), SkipVersionMismatchCheck()),
Run: func(_ *cobra.Command, _ []string) {
installer.Force = installerParams.Force
installer.RunEnvironment = installerParams.RunEnvironment
Expand Down

0 comments on commit f4ce24a

Please sign in to comment.