Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(clipper/options): Enhance version handling and remove pointers for improved usability #37

Merged
merged 2 commits into from
Jun 30, 2024

Conversation

supitsdu
Copy link
Owner

@supitsdu supitsdu commented Jun 30, 2024

This pull request enhances our Clipper codebase by addressing version management and configuration handling:

  • Implemented dynamic versioning to distinguish between development builds ("dev git/source") and release builds ("vX.Y.Z OS/ARCH").

Tasks:

  • Modified options.go to use package-level variables for version information and provide a GetVersion() function.
  • Updated the Makefile to set version and build metadata using -ldflags.
  • Adjusted main.go to utilize GetVersion() for displaying the version.
  • Refactored options.Config by removing unnecessary pointers from the DirectText and ShowVersion fields.
  • Updated unit tests to accommodate changes.

Benefits:

  • Improved clarity and user-friendliness of version information.
  • Simplified code and reduced potential for errors by eliminating pointers.

Closes #36
Closes #30

supitsdu added 2 commits June 30, 2024 18:41
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).
@supitsdu supitsdu added enhancement New feature requests or enhancements. refactoring Issues or PRs to improving code structure, without changing its external behavior cleanup Minor changes to remove dead code, fix inconsistencies, etc. usability labels Jun 30, 2024
@supitsdu supitsdu self-assigned this Jun 30, 2024
@supitsdu supitsdu merged commit ed7d6bd into main Jun 30, 2024
1 check passed
@supitsdu supitsdu deleted the refactor/options-and-version-improvements branch June 30, 2024 22:59
BuildMetadata = "git/source" // Default for development builds
)

// GetVersion formats the version string for display
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Minor changes to remove dead code, fix inconsistencies, etc. enhancement New feature requests or enhancements. refactoring Issues or PRs to improving code structure, without changing its external behavior usability
Projects
None yet
2 participants