Skip to content

Commit

Permalink
Merge pull request #85 from kozmod/dev
Browse files Browse the repository at this point in the history
Dev to Main
  • Loading branch information
kozmod committed Jun 3, 2023
2 parents c5a3e2b + 9ff933c commit 67c3b10
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ProGen <img align="right" src=".github/assets/PG1-4-3-1.png" alt="drawing" width="60" />

![test](https://github.com/kozmod/progen/actions/workflows/test.yml/badge.svg)
[![test](https://github.com/kozmod/progen/actions/workflows/test.yml/badge.svg)](https://github.com/kozmod/progen/actions/workflows/test.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/kozmod/progen)](https://goreportcard.com/report/github.com/kozmod/progen)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/kozmod/progen)
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/kozmod/progen)
![GitHub release date](https://img.shields.io/github/release-date/kozmod/progen)
![GitHub last commit](https://img.shields.io/github/last-commit/kozmod/progen)
![GitHub MIT license](https://img.shields.io/github/license/kozmod/progen)
[![GitHub MIT license](https://img.shields.io/github/license/kozmod/progen)](https://github.com/kozmod/progen/blob/main/LICENSE)

A flexible, language and frameworks agnostic tool that allows you to generate projects structure from templates based
on `yaml` configuration (generate directories, files and execute commands).
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.19

require (
github.com/go-resty/resty/v2 v2.7.0
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.24.0
golang.org/x/sync v0.1.0
golang.org/x/sync v0.2.0
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -16,5 +16,5 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
golang.org/x/net v0.0.0-20211030010937-7b24c0a3601d // indirect
)
17 changes: 7 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,30 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/net v0.0.0-20211030010937-7b24c0a3601d h1:qq9MRNuAi2Z/hwPc3ltvEhaCKOsXtip4L3j483X488w=
golang.org/x/net v0.0.0-20211030010937-7b24c0a3601d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
10 changes: 9 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"golang.org/x/xerrors"
"gopkg.in/yaml.v3"

"github.com/kozmod/progen/internal/entity"
)
Expand Down Expand Up @@ -43,11 +44,18 @@ type Section[T any] struct {

type File struct {
Path string `yaml:"path"`
Data *string `yaml:"data"`
Data *Bytes `yaml:"data"`
Get *Get `yaml:"get"`
Local *string `yaml:"local"`
}

type Bytes []byte

func (fd *Bytes) UnmarshalYAML(node *yaml.Node) error {
*fd = Bytes(node.Value)
return nil
}

type Command struct {
Dir string `yaml:"dir"`
Exec string `yaml:"exec"`
Expand Down
8 changes: 4 additions & 4 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func Test_ValidateFile(t *testing.T) {
t.Run("not_error_when_data_is_not_nil", func(t *testing.T) {
in := File{
Path: path,
Data: func(s string) *string { return &s }("some data"),
Data: func(d Bytes) *Bytes { return &d }(Bytes("some data")),
Get: nil,
}
err := ValidateFile(in)
Expand All @@ -144,7 +144,7 @@ func Test_ValidateFile(t *testing.T) {
t.Run("error_when_data_and_get_are_not_nil_both", func(t *testing.T) {
in := File{
Path: path,
Data: func(s string) *string { return &s }("some data"),
Data: func(d Bytes) *Bytes { return &d }(Bytes("some data")),
Get: &Get{},
}
err := ValidateFile(in)
Expand Down Expand Up @@ -272,7 +272,7 @@ cmd2:
file := files.Val[0]
a.Equal("x/DDDDDD", file.Path)
a.NotNil(file.Data)
a.Equal("ENV GOPROXY \"{{.vars.GOPROXY}} ,proxy.golang.org,direct\"\n", *file.Data)
a.Equal(Bytes("ENV GOPROXY \"{{.vars.GOPROXY}} ,proxy.golang.org,direct\"\n"), *file.Data)
})

t.Run("success_unmarshal_skip_all_cmd_and_dirs2_sections", func(t *testing.T) {
Expand Down Expand Up @@ -333,7 +333,7 @@ cmd2:
file := files.Val[0]
a.Equal("x/DDDDDD", file.Path)
a.NotNil(file.Data)
a.Equal("ENV GOPROXY \"{{.vars.GOPROXY}} ,proxy.golang.org,direct\"\n", *file.Data)
a.Equal(Bytes("ENV GOPROXY \"{{.vars.GOPROXY}} ,proxy.golang.org,direct\"\n"), *file.Data)
})
t.Run("error_when-config_not_contains_executable_actions", func(t *testing.T) {
const (
Expand Down
2 changes: 1 addition & 1 deletion internal/factory/file_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewFileExecutor(
case f.Data != nil:
file := entity.DataFile{
FileInfo: tmpl,
Data: []byte(*f.Data),
Data: *f.Data,
}
producer = exec.NewDummyProducer(file)
case f.Get != nil:
Expand Down

0 comments on commit 67c3b10

Please sign in to comment.