Skip to content

Commit 48e5aa6

Browse files
authored
fix(CLI): Fixing CLI version command (#3198)
1 parent 7115ccb commit 48e5aa6

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

cli/cmd/config.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ func teardownCommand(cmd *cobra.Command, args []string) {
152152
}
153153

154154
func setupVersion() {
155-
versionText, isVersionMatch = config.GetVersion(
156-
context.Background(),
157-
cliConfig,
158-
config.GetAPIClient(cliConfig),
159-
)
155+
versionText, isVersionMatch = config.GetVersion(context.Background(), cliConfig)
160156
}
161157

162158
func validateVersionMismatch() {

cli/config/version.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,29 @@ import (
99

1010
const defaultVersionExtension = "json"
1111

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

15+
if cfg.UIEndpoint != "" {
16+
scheme, endpoint, path, _ := ParseServerURL(cfg.UIEndpoint)
17+
cfg.Scheme = scheme
18+
cfg.Endpoint = endpoint
19+
cfg.ServerPath = path
20+
}
21+
client := GetAPIClient(cfg)
22+
1523
if cfg.IsEmpty() {
1624
return result + `
1725
Server: Not Configured`, false
1826
}
1927

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

34+
version := meta.GetVersion()
2635
isVersionMatch := version == Version
2736
if isVersionMatch {
2837
version += `
@@ -33,17 +42,6 @@ Server: Failed to get the server version - %s`, err.Error()), false
3342
Server: %s`, version), isVersionMatch
3443
}
3544

36-
func getServerVersion(ctx context.Context, client *openapi.APIClient) (string, error) {
37-
resp, _, err := client.ApiApi.
38-
GetVersion(ctx, defaultVersionExtension).
39-
Execute()
40-
if err != nil {
41-
return "", err
42-
}
43-
44-
return resp.GetVersion(), nil
45-
}
46-
4745
func getVersionMetadata(ctx context.Context, client *openapi.APIClient) (*openapi.Version, error) {
4846
resp, _, err := client.ApiApi.
4947
GetVersion(ctx, defaultVersionExtension).

0 commit comments

Comments
 (0)