Skip to content

Commit

Permalink
fix(CLI): Fixing CLI version command (#3198)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Oct 2, 2023
1 parent 7115ccb commit 48e5aa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
6 changes: 1 addition & 5 deletions cli/cmd/config.go
Expand Up @@ -152,11 +152,7 @@ func teardownCommand(cmd *cobra.Command, args []string) {
}

func setupVersion() {
versionText, isVersionMatch = config.GetVersion(
context.Background(),
cliConfig,
config.GetAPIClient(cliConfig),
)
versionText, isVersionMatch = config.GetVersion(context.Background(), cliConfig)
}

func validateVersionMismatch() {
Expand Down
24 changes: 11 additions & 13 deletions cli/config/version.go
Expand Up @@ -9,20 +9,29 @@ import (

const defaultVersionExtension = "json"

func GetVersion(ctx context.Context, cfg Config, client *openapi.APIClient) (string, bool) {
func GetVersion(ctx context.Context, cfg Config) (string, bool) {
result := fmt.Sprintf(`CLI: %s`, Version)

if cfg.UIEndpoint != "" {
scheme, endpoint, path, _ := ParseServerURL(cfg.UIEndpoint)
cfg.Scheme = scheme
cfg.Endpoint = endpoint
cfg.ServerPath = path
}
client := GetAPIClient(cfg)

if cfg.IsEmpty() {
return result + `
Server: Not Configured`, false
}

version, err := getServerVersion(ctx, client)
meta, err := getVersionMetadata(ctx, client)
if err != nil {
return result + fmt.Sprintf(`
Server: Failed to get the server version - %s`, err.Error()), false
}

version := meta.GetVersion()
isVersionMatch := version == Version
if isVersionMatch {
version += `
Expand All @@ -33,17 +42,6 @@ Server: Failed to get the server version - %s`, err.Error()), false
Server: %s`, version), isVersionMatch
}

func getServerVersion(ctx context.Context, client *openapi.APIClient) (string, error) {
resp, _, err := client.ApiApi.
GetVersion(ctx, defaultVersionExtension).
Execute()
if err != nil {
return "", err
}

return resp.GetVersion(), nil
}

func getVersionMetadata(ctx context.Context, client *openapi.APIClient) (*openapi.Version, error) {
resp, _, err := client.ApiApi.
GetVersion(ctx, defaultVersionExtension).
Expand Down

0 comments on commit 48e5aa6

Please sign in to comment.