Skip to content

Commit

Permalink
allow using any name format (kebab, camel etc.) in the application na…
Browse files Browse the repository at this point in the history
…me field (#116)
  • Loading branch information
moshebe committed Mar 12, 2021
1 parent 2796796 commit 6e260e1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/gin-gonic/gin v1.6.3
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.6.8
github.com/iancoleman/strcase v0.1.3
github.com/manifoldco/promptui v0.8.0
github.com/pkg/browser v0.0.0-20201112035734-206646e67786
github.com/pkg/errors v0.9.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/iancoleman/strcase v0.1.3 h1:dJBk1m2/qjL1twPLf68JND55vvivMupZ4wIzE8CTdBw=
github.com/iancoleman/strcase v0.1.3/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
Expand Down
5 changes: 4 additions & 1 deletion pkg/config/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"io"

"github.com/iancoleman/strcase"
"github.com/moshebe/gebug/pkg/render"
"github.com/pkg/errors"
)
Expand All @@ -23,7 +24,9 @@ func (c *Config) renderedWrite(template string, writer io.Writer) error {

// RenderDockerComposeFile writes the docker-compose.yml configuration to writer
func (c *Config) RenderDockerComposeFile(writer io.Writer) error {
return c.renderedWrite(`version: '3'
cfg := *c
cfg.Name = strcase.ToKebab(cfg.Name)
return cfg.renderedWrite(`version: '3'
services:
gebug-{{.Name}}:
build:
Expand Down
21 changes: 21 additions & 0 deletions pkg/config/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ var mockConfig = &Config{
ExposePorts: []string{"8080"},
}

func TestConfig_RenderDockerComposeFileCamlCaseAppName(t *testing.T) {
cfg := *mockConfig
cfg.Name = "myApp2"
out := bytes.NewBufferString("")
err := cfg.RenderDockerComposeFile(out)
assert.NoError(t, err)
assert.Equal(t,
`version: '3'
services:
gebug-my-app-2:
build:
context: ..
dockerfile: .gebug/Dockerfile
volumes:
- ../:/src:ro
ports:
- 8080
`,
out.String())
}

func TestConfig_RenderDockerComposeFile(t *testing.T) {
out := bytes.NewBufferString("")
err := mockConfig.RenderDockerComposeFile(out)
Expand Down

0 comments on commit 6e260e1

Please sign in to comment.