From 1399a396036ea246522a4cbae7aef376d6dbbda2 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 29 Dec 2016 10:55:35 -0200 Subject: [PATCH] fixed formula naming --- brew/brew.go | 9 +++++++-- brew/brew_test.go | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 brew/brew_test.go diff --git a/brew/brew.go b/brew/brew.go index f0ec1e7ed..e0f33e03d 100644 --- a/brew/brew.go +++ b/brew/brew.go @@ -96,9 +96,8 @@ func dataFor(version string, config config.ProjectConfig, client *github.Client) } else { description = *rep.Description } - // TODO deal with `-`, `_` and other stuff on binary name return templateData{ - Name: strings.Title(config.BinaryName), + Name: formulaNameFor(config.BinaryName), Desc: description, Homepage: homepage, Repo: config.Repo, @@ -106,3 +105,9 @@ func dataFor(version string, config config.ProjectConfig, client *github.Client) BinaryName: config.BinaryName, }, err } + +func formulaNameFor(name string) string { + name = strings.Replace(name, "-", " ", -1) + name = strings.Replace(name, "_", " ", -1) + return strings.Replace(strings.Title(name), " ", "", -1) +} \ No newline at end of file diff --git a/brew/brew_test.go b/brew/brew_test.go new file mode 100644 index 000000000..1d0f218eb --- /dev/null +++ b/brew/brew_test.go @@ -0,0 +1,18 @@ +package brew + +import ( + "testing" + "github.com/docker/docker/pkg/testutil/assert" +) + +func TestNameWithDash(t *testing.T) { + assert.Equal(t, formulaNameFor("some-binary"), "SomeBinary") +} + +func TestNameWithUnderline(t *testing.T) { + assert.Equal(t, formulaNameFor("some_binary"), "SomeBinary") +} + +func TestSimpleName(t *testing.T) { + assert.Equal(t, formulaNameFor("binary"), "Binary") +}