Conversation
danvergara
reviewed
Dec 4, 2023
Comment on lines
+16
to
+66
|
|
||
| ```golang | ||
| type Details struct { | ||
| Name string | ||
| } | ||
| ``` | ||
|
|
||
| Crea un directorio de assets con tus templates de proyecto para utilizarlo en tu proyecto. | ||
|
|
||
| ```golang | ||
| //go:embed assets/* | ||
| var assets embed.FS | ||
| ``` | ||
|
|
||
| Crea una estructura que implemente la interfaz `Generator` con el m'etodo `Run(cfg *config.Cfg)` y utiliza las funciones del paquete `files` para poder realizar las copias de archivos, directorios y generaci'on de templates. | ||
|
|
||
| ```golang | ||
| package cli | ||
|
|
||
| import ( | ||
| "github.com/gophers-mx/just-go/config" | ||
| "github.com/gophers-mx/just-go/pkg/files" | ||
| ) | ||
|
|
||
| type CustomGenerator struct {} | ||
|
|
||
| func (lg *CustomGenerator) Run(cfg *config.Cfg) { | ||
| files.GenFromTemplate("assets", "", "README.md") | ||
| files.CopyDirectory("assets/cmd", "cmd") | ||
| files.CopyFile("assets", "", "hello.md") | ||
| } | ||
| ``` | ||
|
|
||
| Crea una instancia de la estructura `Generathor` y ejecuta su m'etodo `Run()`. | ||
|
|
||
| ```golang | ||
| func main() { | ||
| generathor := &justgo.Generathor{ | ||
| Assets: assets, | ||
| ProjectName: "hello world", | ||
| Generator: cli.NewGeneratorCLI(), | ||
| TemplateDetails: Details{ | ||
| Name: "hello world", | ||
| }, | ||
| } | ||
|
|
||
| generathor.Run() | ||
| } | ||
| ``` | ||
|
|
||
| Puedes encontrar un ejemplo completo [aqui](https://github.com/4k1k0/gen-cli). |
Member
There was a problem hiding this comment.
Por qué exponer el proyecto como una librería si estaba pensado a ser una CLI?
Member
Author
There was a problem hiding this comment.
Para ser más flexibles con los templates. Aunque estaba pensando menter un cli aquí mismo con un template. Así puede ser ambas. ¿Cómo ven?
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.
Cambia la descripcion del proyecto para indicar como crear cli personalizados.