mirror of
https://github.com/onyx-and-iris/gignore.git
synced 2025-04-01 19:23:51 +01:00
Compare commits
6 Commits
f0b64e3a75
...
eaf091dc1a
Author | SHA1 | Date | |
---|---|---|---|
eaf091dc1a | |||
99871a9040 | |||
1ca4304806 | |||
59521e1cd0 | |||
fcb23a3c01 | |||
c2b7dfcb18 |
15
README.md
15
README.md
@ -7,6 +7,13 @@
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
With Go tools:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go generate ./...
|
||||||
|
go install ./cmd/gignore
|
||||||
|
```
|
||||||
|
|
||||||
With [Task][task]:
|
With [Task][task]:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -37,7 +44,7 @@ Example:
|
|||||||
|
|
||||||
## Custom Templates
|
## Custom Templates
|
||||||
|
|
||||||
It's possible to add your own custom templates, simply create a directory in `internal/registry/templates`. You'll need to rebuild the project before you can load the new templates.
|
It's possible to add your own custom templates, simply create a directory in `internal/registry/templates`. You'll need to [reinstall](https://github.com/onyx-and-iris/gignore?tab=readme-ov-file#install) the project before you can load the new templates.
|
||||||
|
|
||||||
Then pass the dir name as a flag, for example:
|
Then pass the dir name as a flag, for example:
|
||||||
|
|
||||||
@ -53,11 +60,11 @@ If a template is requested but not found in the custom directory then the gitign
|
|||||||
|
|
||||||
[gitignore.io][gitignoreio] For providing such a useful .gitignore service
|
[gitignore.io][gitignoreio] For providing such a useful .gitignore service
|
||||||
|
|
||||||
[mh-cbon][mh-cbon] For writing the [gigo][gigo] client library for gitignore.io
|
[cuonglm][cuonglm] For writing the [gogi][gogi] client library for gitignore.io
|
||||||
|
|
||||||
|
|
||||||
[task]: https://taskfile.dev/
|
[task]: https://taskfile.dev/
|
||||||
[gitignoreio]: https://www.toptal.com/developers/gitignore
|
[gitignoreio]: https://www.toptal.com/developers/gitignore
|
||||||
[mh-cbon]: https://github.com/mh-cbon
|
[cuonglm]: https://github.com/cuonglm
|
||||||
[gigo]: https://github.com/mh-cbon/gigo
|
[gogi]: https://github.com/cuonglm/gogi
|
||||||
[ignore]: https://github.com/neptship/ignore
|
[ignore]: https://github.com/neptship/ignore
|
||||||
|
@ -23,13 +23,6 @@ tasks:
|
|||||||
- task: build-windows
|
- task: build-windows
|
||||||
- task: build-linux
|
- task: build-linux
|
||||||
|
|
||||||
release:
|
|
||||||
desc: Generate the gitignore.io templates and then build the gignore project for Windows and Linux
|
|
||||||
deps: [generate]
|
|
||||||
cmds:
|
|
||||||
- task: build-windows
|
|
||||||
- task: build-linux
|
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
desc: Vet the code
|
desc: Vet the code
|
||||||
deps: [fmt]
|
deps: [fmt]
|
||||||
@ -44,7 +37,7 @@ tasks:
|
|||||||
generate:
|
generate:
|
||||||
desc: Generate the gitignore.io templates
|
desc: Generate the gitignore.io templates
|
||||||
cmds:
|
cmds:
|
||||||
- go generate .
|
- go generate ./...
|
||||||
|
|
||||||
build-windows:
|
build-windows:
|
||||||
desc: Build the gignore project for Windows
|
desc: Build the gignore project for Windows
|
||||||
|
@ -20,10 +20,25 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errChan := make(chan error)
|
||||||
|
doneChan := make(chan struct{})
|
||||||
|
|
||||||
for _, template := range templates {
|
for _, template := range templates {
|
||||||
err := createTemplate(template)
|
go func() {
|
||||||
if err != nil {
|
err := createTemplate(template)
|
||||||
fmt.Fprintf(os.Stderr, "Failed to create template %s: %v\n", template.Name, err)
|
if err != nil {
|
||||||
|
errChan <- fmt.Errorf("Failed to create template %s: %v", template.Name, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
doneChan <- struct{}{}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
for range templates {
|
||||||
|
select {
|
||||||
|
case err := <-errChan:
|
||||||
|
log.Error(err)
|
||||||
|
case <-doneChan:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go run cmd/gen/gen.go
|
//go:generate go run cmd/gen/main.go
|
||||||
|
|
||||||
// Client is a client for managing .gitignore templates.
|
// Client is a client for managing .gitignore templates.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
@ -32,7 +32,7 @@ func New(options ...Option) *Client {
|
|||||||
|
|
||||||
// List returns a list of available .gitignore templates.
|
// List returns a list of available .gitignore templates.
|
||||||
func (c *Client) List() ([]string, error) {
|
func (c *Client) List() ([]string, error) {
|
||||||
return c.registry.ListTemplates()
|
return c.registry.List()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create generates a .gitignore file from the specified template.
|
// Create generates a .gitignore file from the specified template.
|
||||||
@ -60,7 +60,7 @@ func (c *Client) Create(template string) error {
|
|||||||
log.Infof("template '%s' found in default gitignoreio registry", template)
|
log.Infof("template '%s' found in default gitignoreio registry", template)
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := c.registry.GetTemplate(template)
|
content, err := c.registry.Get(template)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@ func (t *TemplateRegistry) Contains(name string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTemplate retrieves the content of the gitignore template with the given name.
|
// Get retrieves the content of the gitignore template with the given name.
|
||||||
func (t *TemplateRegistry) GetTemplate(name string) ([]byte, error) {
|
func (t *TemplateRegistry) Get(name string) ([]byte, error) {
|
||||||
data, err := fs.ReadFile(t.templates, t.filePath(name))
|
data, err := fs.ReadFile(t.templates, t.filePath(name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -50,8 +50,8 @@ func (t *TemplateRegistry) GetTemplate(name string) ([]byte, error) {
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListTemplates lists all the gitignore templates in the registry.
|
// List lists all the gitignore templates in the registry.
|
||||||
func (t *TemplateRegistry) ListTemplates() ([]string, error) {
|
func (t *TemplateRegistry) List() ([]string, error) {
|
||||||
var paths []string
|
var paths []string
|
||||||
|
|
||||||
err := fs.WalkDir(
|
err := fs.WalkDir(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user