refactor: Better Command Organization#28
Merged
Conversation
Commands have been reorganized into subpackages (entries, history, setup, tracking) for better modularity. Project name detection logic is now centralized in internal/project with a new DetectConfiguredProject function, replacing the previous DetectProjectName usage throughout the codebase.
Converted the edit and manual entry commands to return *cobra.Command from functions instead of using package-level variables. This improves modularity and testability, and aligns with best practices for Cobra command structure.
Refactored the delete command to use a function (DeleteCmd) that returns a *cobra.Command instead of a package-level variable. Removed the init() function and moved flag registration into DeleteCmd. This improves modularity and aligns with best practices for Cobra command structure.
Converted pause, resume, start, status, and stop commands from package-level variables to constructor functions returning *cobra.Command. This improves testability and modularity by avoiding global state and making command registration more explicit.
Replaces global command variables and init() registration with exported constructor functions (e.g., ExportCmd, LogCmd, StatsCmd, InitCmd, VersionCmd) for each command. This improves modularity and testability by allowing commands to be instantiated and registered explicitly.
Replaces the global rootCmd variable with a RootCmd() function that constructs the root command and adds subcommands for tracking, history, entries, and setup. This modularizes command registration and improves maintainability.
Moved version-related code and tests from cmd to cmd/utilities for better organization. Updated .goreleaser.yml and root command to reference the new location.
Revised CLAUDE.md and CONTRIBUTING.md to reflect the new organization of CLI commands into subdirectories and the use of constructor functions for command registration. Updated project structure diagrams and descriptions to match the current codebase layout, including new directories and changes to project detection logic.
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.
Pull Request Checklist
mainbranch of tmpo.Closes #27
Description
This pull request restructures the CLI command organization, updates documentation to match the new structure, and changes how version information is injected at build time. It also removes the old
edit.goanddelete.gocommand files, reflecting a migration to a new command layout using subdirectories for better maintainability and clarity.Command Structure and Codebase Organization:
cmd/(e.g.,tracking/,entries/,history/,setup/,utilities/) instead of single files per command. Each command is now implemented as a constructor function returning*cobra.Commandand registered explicitly inroot.go. [1] [2] [3]cmd/edit.goandcmd/delete.gohave been removed, indicating these commands have been migrated to the new structure. [1] [2]Documentation Updates:
CONTRIBUTING.mdandCLAUDE.mdto reflect the new subdirectory-based organization and the move of project detection logic frominternal/project/detector.gotointernal/project/detect.go. [1] [2] [3] [4] [5]Build and Version Injection:
.goreleaser.yml) is updated to inject version, commit, and date information into the newcmd/utilitiespackage instead of the oldcmdpackage, and documentation is updated accordingly. [1] [2] [3] [4]Internal Logic Changes:
internal/project.DetectConfiguredProject()instead of the previouscmd/start.go:DetectProjectName(), and the file location is updated in the documentation. [1] [2]These changes modernize the codebase structure, improve maintainability, and ensure documentation and build configuration stay in sync with the code.