-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(cli): version display improvements (#2505)
- Loading branch information
Showing
27 changed files
with
554 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
openapi: 3.0.0 | ||
components: | ||
schemas: | ||
Version: | ||
type: object | ||
properties: | ||
version: | ||
type: string | ||
example: 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package actions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/kubeshop/tracetest/cli/config" | ||
) | ||
|
||
type VersionConfig struct{} | ||
|
||
type versionAction struct { | ||
actionAgs | ||
} | ||
|
||
var _ Action[VersionConfig] = &versionAction{} | ||
|
||
func NewGetServerVersionAction(options ...ActionArgsOption) versionAction { | ||
args := NewActionArgs(options...) | ||
return versionAction{actionAgs: args} | ||
} | ||
|
||
func (a versionAction) Run(ctx context.Context, args VersionConfig) error { | ||
versionText := a.GetVersionText(ctx) | ||
|
||
fmt.Println(versionText) | ||
return nil | ||
} | ||
|
||
func (a versionAction) GetVersionText(ctx context.Context) string { | ||
result := fmt.Sprintf(`CLI: %s`, config.Version) | ||
|
||
if a.config.IsEmpty() { | ||
return result + ` | ||
Server: Not Configured` | ||
} | ||
|
||
version, err := a.GetServerVersion(ctx) | ||
if err != nil { | ||
return result + fmt.Sprintf(` | ||
Server: Failed to get the server version - %s`, err.Error()) | ||
} | ||
|
||
isVersionMatch := version == config.Version | ||
if isVersionMatch { | ||
version += ` | ||
✔️ Version match` | ||
} else { | ||
version += ` | ||
✖️ Version mismatch` | ||
} | ||
|
||
return result + fmt.Sprintf(` | ||
Server: %s`, version) | ||
} | ||
|
||
func (a versionAction) GetServerVersion(ctx context.Context) (string, error) { | ||
if a.config.IsEmpty() { | ||
return "", fmt.Errorf("not Configured") | ||
} | ||
|
||
req := a.client.ApiApi.GetVersion(ctx) | ||
version, _, err := req.Execute() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return *version.Version, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.