Skip to content

refactor: Cobra integration cleanup#102

Merged
mroth merged 8 commits intomasterfrom
cobra-cleanup
Jul 27, 2025
Merged

refactor: Cobra integration cleanup#102
mroth merged 8 commits intomasterfrom
cobra-cleanup

Conversation

@mroth
Copy link
Owner

@mroth mroth commented Jul 18, 2025

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=homebrew ldflag which will show up in the version information..

mroth added 5 commits July 18, 2025 16:52
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.
mroth added 2 commits July 27, 2025 17:40
CRITICAL: This will require modifying the homebrew-core formulae to pass
appropriate builtBy flags on the next version release:
@mroth mroth changed the title refactor: Cobra integration cleanup (WIP) refactor: Cobra integration cleanup Jul 27, 2025
@mroth
Copy link
Owner Author

mroth commented Jul 27, 2025

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.

@mroth mroth marked this pull request as ready for review July 27, 2025 21:51
@mroth mroth requested a review from Copilot July 27, 2025 21:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.
@mroth mroth merged commit 7d7b7fe into master Jul 27, 2025
17 checks passed
@mroth mroth deleted the cobra-cleanup branch July 27, 2025 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants