-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat: add generate controller cli #39
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trop cool 🔥
Beaucoup de coms mais en majorité c'est pas des erreurs, c'est plus des demandes de features. Limite on pourrait les mettre dans une autre PR
d8d513a
to
5476700
Compare
5476700
to
06b5835
Compare
06b5835
to
a4a610b
Compare
cmd/fuego/commands/controller.go
Outdated
) | ||
|
||
func ControllerCommand() *cli.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On l'appelle de l'extérieur commands.Controller
donc on comprend que c'est la commande pour créer des controllers
func createController(controllerName string) error { | ||
controllerDir := "./controllers/" | ||
if _, err := os.Stat(controllerDir); os.IsNotExist(err) { | ||
err = os.Mkdir(controllerDir, 0755) | ||
err = os.Mkdir(controllerDir, 0o755) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je mets explicitement que c'est de l'octal
|
||
newContent := strings.ReplaceAll(string(templateContent), "newController", controllerName) | ||
newContent = strings.ReplaceAll(newContent, "NewController", strings.Title(controllerName)) | ||
newContent = strings.ReplaceAll(newContent, "NewController", titler.String(controllerName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
askip mon IDE me dit qu'il faut préférer utiliser cases
func TestCreateController(t *testing.T) { | ||
err := createController("books") | ||
require.NoError(t, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ca fait toujours plez pour vérifier que rien ne crash :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renommé parce que comme ça on est sûrs de pas faire de bêtises, on a le formattting, les imports etc...
GetNewController(id string) (NewController, error) | ||
CreateNewController(NewControllerCreate) (NewController, error) | ||
GetAllNewController() ([]NewController, error) | ||
UpdateNewController(id string, input NewControllerUpdate) (NewController, error) | ||
DeleteNewController(id string) (any, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai rajouté un corps aux fonctions et les signatures d'interface :
Comme ça, plus qu'à implémenter les interfaces (faire la partie BDD) et on a notre CRUD fini !
controllerName := cCtx.Args().First() | ||
|
||
if controllerName == "" { | ||
controllerName = "newController" | ||
fmt.Println("Note: You can add a controller name as an argument. Example: `fuego controller books`") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'abord on prend la valeur, et seulement si elle n'est pas précisée, on lui assigne la valeur par défaut
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "output", | ||
Usage: "output file", | ||
Aliases: []string{"o"}, | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ce sera une feature demandée je pense
@@ -7,6 +7,9 @@ import ( | |||
) | |||
|
|||
func TestCreateController(t *testing.T) { | |||
err := createController("books") | |||
res, err := createController("books", "/dev/null") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Et on peut direct utiliser notre feature pour que les tests polluent pas notre workspace :)
command
fuego controller myController
will generate./controller/myController.go
file