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

Doc #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Doc #6

wants to merge 1 commit into from

Conversation

4k1k0
Copy link
Member

@4k1k0 4k1k0 commented Dec 4, 2023

Cambia la descripcion del proyecto para indicar como crear cli personalizados.

@4k1k0 4k1k0 requested review from ChewRafa and danvergara December 4, 2023 10:42
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).
Copy link
Member

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?

Copy link
Member Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants