-
Notifications
You must be signed in to change notification settings - Fork 2
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
Doc #6
base: main
Are you sure you want to change the base?
Conversation
|
||
```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). |
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.
Por qué exponer el proyecto como una librería si estaba pensado a ser una CLI?
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.
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?
Cambia la descripcion del proyecto para indicar como crear cli personalizados.