Skip to content

Refactor: Integrate Cobra CLI and update Go version#14

Merged
TheYkk merged 1 commit intomasterfrom
feat/cobra-cli-integration
May 20, 2025
Merged

Refactor: Integrate Cobra CLI and update Go version#14
TheYkk merged 1 commit intomasterfrom
feat/cobra-cli-integration

Conversation

@TheYkk
Copy link
Owner

@TheYkk TheYkk commented May 20, 2025

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 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.
@TheYkk TheYkk merged commit d6741b1 into master May 20, 2025
0 of 2 checks passed
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.

1 participant