Conversation
This commit refactors the version management in Clipper: - Introduces package-level variables `Version` and `BuildMetadata` in `options.go` with "dev" and "git/source" defaults for development builds. - Adds the `GetVersion()` function to format the version string for display, incorporating build metadata when available. - Updates the Makefile to inject the correct version and build metadata using `-ldflags` during compilation. - Modifies `main.go` to use `GetVersion()` for consistent version display. Now, Clipper displays "dev git/source" when run from source and a tagged version with OS/ARCH information (e.g., "v1.5.0 linux/amd64") when run from a built binary. This improves clarity for users and maintainers alike. Issue #36
This commit refactors the `options.Config` struct by changing the `DirectText` and `ShowVersion` fields from pointers (`*string` and `*bool`) to their corresponding value types (`string` and `bool`). The use of pointers was initially introduced to accommodate the return type of `flag.String` and `flag.Bool` in the `ParseFlags` function. However, it resulted in unnecessary complexity and the potential for nil pointer dereferences. By removing the pointers, the code becomes simpler, more readable, and less error-prone. It also eliminates the need to constantly dereference pointers when accessing the values of these fields. Issue #30: Refactor options.Config to Remove Pointer for DirectText (Improving Usability and Testing).
5 tasks
ccoVeille
suggested changes
Jun 30, 2024
| BuildMetadata = "git/source" // Default for development builds | ||
| ) | ||
|
|
||
| // GetVersion formats the version string for display |
Contributor
There was a problem hiding this comment.
// GetVersion formats the version string for display
func GetVersion() string {
display := strings.TrimSpace(Version)
if BuildMetadata != "" {
- return strings.TrimSpace(Version) + " " + strings.TrimSpace(BuildMetadata)
- } else {
- return strings.TrimSpace(Version)
display += " "+ strings.TrimSpace(BuildMetadata)
}
return display
}
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances our Clipper codebase by addressing version management and configuration handling:
Tasks:
options.goto use package-level variables for version information and provide aGetVersion()function.-ldflags.main.goto utilizeGetVersion()for displaying the version.options.Configby removing unnecessary pointers from theDirectTextandShowVersionfields.Benefits:
Closes #36
Closes #30