Conversation
This is a more standard style. For now, it makes our version setting a bit more messy, but we are likely to refactor that during this soon anyhow.
Shift from using the Cobra documentation recommended method of global variables and an init() function to using a more idiomatic NewCmd pattern, as used by goreleaser.
CRITICAL: This will require modifying the homebrew-core formulae to pass appropriate builtBy flags on the next version release:
Owner
Author
|
I feel like this gets the basic structure towards something fairly modern, and we can add nice things like Fang integration in the future, but this PR will remain confined to cleanup stuff. |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Cobra CLI integration to modernize the codebase structure and adopt current best practices. The refactoring centralizes command creation, improves error handling patterns, and integrates a third-party version management library.
- Restructures command organization by moving from global variables to factory functions
- Replaces manual error handling with proper Cobra error return patterns
- Integrates go-version library for enhanced version information display
Reviewed Changes
Copilot reviewed 14 out of 43 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| main.go | Replaces manual command setup with centralized execution and go-version integration |
| internal/cmd/root.go | Creates new root command structure with factory pattern and centralized command registration |
| internal/cmd/*/**.go | Converts command definitions from global variables to factory functions with improved error handling |
| internal/commands/debug/debug.go | Removes old debug command structure (replaced by new location) |
| go.mod | Adds go-version dependency for version management |
| .goreleaser.yml | Updates build flags to populate version metadata |
| features/command_init.feature | Updates test expectation for new error message format |
| docs/banner.txt | Adds ASCII art banner for version display |
NOTE: when testing, if you want to force an error to test, an easy way is to run `scmpuff init --shell=unknown` to trigger an error.
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.
Much has likely changed with how Cobra works over the past decade or so. Draft PR branch to chip away at cleaning up towards modern best practices for library structure when I have spare moments between calls.
👋 Drive by comments or ideas very welcome from folks who know what good Cobra projects look like these days.
🤬CodeFactor seems to want to throw build failures on CI because filename changes cause it to think ancient issues are new ones, need to figure out how to change that setting too!
Important
As a result of the go-version integration here, we're going to want to modify the public homebrew-core formula for scmpuff before the next release, so that we can pass a
builtBy=homebrewldflag which will show up in the version information..