Skip to content
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

Merged
merged 3 commits into from
Feb 9, 2024
Merged

Conversation

rizerkrof
Copy link
Collaborator

command fuego controller myController will generate ./controller/myController.go file

Copy link
Member

@EwenQuim EwenQuim left a 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

cmd/fuego/commands/controller.go Outdated Show resolved Hide resolved
cmd/fuego/commands/controller.go Outdated Show resolved Hide resolved
cmd/fuego/commands/controller.go Outdated Show resolved Hide resolved
cmd/fuego/commands/controller.go Outdated Show resolved Hide resolved
cmd/fuego/templates/controller.template.go Outdated Show resolved Hide resolved
cmd/fuego/templates/controller.template.go Outdated Show resolved Hide resolved
cmd/fuego/templates/controller.template.go Outdated Show resolved Hide resolved
cmd/fuego/templates/embed.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
cmd/fuego/templates/controller.template.go Outdated Show resolved Hide resolved
@rizerkrof rizerkrof force-pushed the feat/cli-for-controllers branch 2 times, most recently from d8d513a to 5476700 Compare February 8, 2024 17:32
)

func ControllerCommand() *cli.Command {
Copy link
Member

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)
Copy link
Member

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))
Copy link
Member

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

Comment on lines 9 to 12
func TestCreateController(t *testing.T) {
err := createController("books")
require.NoError(t, err)
}
Copy link
Member

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 :)

Copy link
Member

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...

Comment on lines +77 to +81
GetNewController(id string) (NewController, error)
CreateNewController(NewControllerCreate) (NewController, error)
GetAllNewController() ([]NewController, error)
UpdateNewController(id string, input NewControllerUpdate) (NewController, error)
DeleteNewController(id string) (any, error)
Copy link
Member

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 !

Comment on lines 27 to 32
controllerName := cCtx.Args().First()

if controllerName == "" {
controllerName = "newController"
fmt.Println("Note: You can add a controller name as an argument. Example: `fuego controller books`")
}
Copy link
Member

@EwenQuim EwenQuim Feb 9, 2024

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

Comment on lines +19 to +25
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Usage: "output file",
Aliases: []string{"o"},
},
},
Copy link
Member

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")
Copy link
Member

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 :)

@rizerkrof rizerkrof merged commit be2016b into main Feb 9, 2024
1 check passed
@EwenQuim EwenQuim deleted the feat/cli-for-controllers branch July 23, 2024 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants