-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add register command for auto-generating model registry #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
beesaferoot
merged 2 commits into
beesaferoot:main
from
DivineUX23:feature/register-command
Jul 11, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,5 @@ main.go.txt | |
| ast_dump.go.txt | ||
| .zed | ||
| gorm-schema | ||
| gorm-schema.exe | ||
| test.log | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| package models | ||
|
|
||
| var ModelTypeRegistry = map[string]interface{}{ | ||
| "Apartment": Apartment{}, | ||
| "Apartment": Apartment{}, | ||
| "ApartmentBookingPrice": ApartmentBookingPrice{}, | ||
| "ApartmentContract": ApartmentContract{}, | ||
| "ApartmentHighlight": ApartmentHighlight{}, | ||
| "Estate": Estate{}, | ||
| "Tenant": Tenant{}, | ||
| "User": User{}, | ||
| } | ||
| "ApartmentContract": ApartmentContract{}, | ||
| "ApartmentHighlight": ApartmentHighlight{}, | ||
| "Estate": Estate{}, | ||
| "Tenant": Tenant{}, | ||
| "User": User{}, | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func RegisterCmd() *cobra.Command { | ||
| return &cobra.Command{ | ||
| Use: "register [path]", | ||
| Short: "Generates model registry file", | ||
| Long: `Scans the given path for Go files containing GORM models (structs embedding gorm.Model) and generates a models_registry.go file. If no path is provided, it defaults to the 'models' directory.`, | ||
| Args: cobra.MaximumNArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
|
|
||
| var pathToValidate string | ||
| if len(args) > 0 { | ||
| pathToValidate = args[0] | ||
| } | ||
|
|
||
| validatedPath, err := validateModelPath(pathToValidate) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to validate model path: %w", err) | ||
| } | ||
|
|
||
| //create model_register.go file: | ||
| ModelRegistry, err := createModelRegisterFile(validatedPath) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create model registry file: %w", err) | ||
| } | ||
|
|
||
| fmt.Printf("Successfully generated model registry: %s\n", ModelRegistry) | ||
| return nil | ||
|
|
||
| }, | ||
| } | ||
| } |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.