Refactor: Integrate Cobra CLI and update Go version#14
Merged
Conversation
This commit refactors the application to use the Cobra CLI framework and updates the Go version and dependencies.
Key changes:
- Updated Go version to 1.24 in `go.mod` and GitHub Actions.
- Added `github.com/spf13/cobra` as a dependency.
- Updated other dependencies to their latest compatible versions.
- Initialized Cobra and created a `cmd` directory for command-line interface code.
- Moved the main application logic into a root command (`cmd/root.go`).
- Created individual Cobra subcommands for existing functionalities:
- `create`: Creates a new git configuration profile.
- `delete`: Deletes an existing git configuration profile.
- `rename`: Renames an existing git configuration profile.
- `edit`: Opens the current git configuration for editing.
- `switch`: Switches the active git configuration profile.
- Helper functions `Hash` and `Write` were made public and moved from `main.go` to `main` package to be accessible by commands. (I initially moved them to `pkg/utils/utils.go` but later refactoring kept them in `main.go` as public functions, which was fine as they are small and specific to this application's core logic).
- `main.go` was updated to simply execute the Cobra root command.
- Basic testing of the commands was performed, confirming core functionality. Commands with multi-step interactive prompts (`rename`, `delete`) were challenging to test fully in the automated environment but their underlying logic is in place.
The application now has a more structured and extensible command-line interface.
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 commit refactors the application to use the Cobra CLI framework and updates the Go version and dependencies.
Key changes:
go.modand GitHub Actions.github.com/spf13/cobraas a dependency.cmddirectory for command-line interface code.cmd/root.go).create: Creates a new git configuration profile.delete: Deletes an existing git configuration profile.rename: Renames an existing git configuration profile.edit: Opens the current git configuration for editing.switch: Switches the active git configuration profile.HashandWritewere made public and moved frommain.gotomainpackage to be accessible by commands. (I initially moved them topkg/utils/utils.gobut later refactoring kept them inmain.goas public functions, which was fine as they are small and specific to this application's core logic).main.gowas updated to simply execute the Cobra root command.rename,delete) were challenging to test fully in the automated environment but their underlying logic is in place.The application now has a more structured and extensible command-line interface.