Skip to content

Commit

Permalink
Merge pull request #4 from abice/ci
Browse files Browse the repository at this point in the history
Added CI
  • Loading branch information
abice authored Aug 14, 2017
2 parents 22b49ea + 7f204e6 commit 5edf28f
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 8 deletions.
35 changes: 35 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 2
jobs:
build:
working_directory: /go/src/github.com/abice/go-enum
docker:
- image: circleci/golang:1.8.1
steps:
- checkout
- run:
name: Install Go Deps
command: |
go get github.com/golang/dep/cmd/dep
go get -v github.com/jteeuwen/go-bindata/...
go get -v golang.org/x/tools/cmd/cover
go get -v github.com/mattn/goveralls
go get -v github.com/modocache/gover
dep ensure
- run:
name: Build
command: |
make build
- run:
name: Test
command: |
make cover
make coveralls
- persist_to_workspace:
root: .
paths: .

workflows:
version: 2
build_and_test:
jobs:
- build:
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
.glide/

/bin
/coverage
/coverage
/vendor
115 changes: 115 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/Masterminds/sprig"

[[constraint]]
name = "github.com/mkideal/cli"

[[constraint]]
name = "github.com/stretchr/testify"

[[constraint]]
name = "golang.org/x/tools"
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ ifdef CIRCLE_ARTIFACTS
SERVICE=circle-ci
endif

PACKAGES='./generator' './example'

.PHONY: all
all: generate fmt build test example cover install

.PHONY: install-deps
install-deps:
glide install

build: generate
go get github.com/golang/dep/cmd/dep
go get -v github.com/jteeuwen/go-bindata/...
go get -v golang.org/x/tools/cmd/cover
go get -v github.com/mattn/goveralls
go get -v github.com/modocache/gover
dep ensure

build:
go generate ./generator
if [ ! -d bin ]; then mkdir bin; fi
go build -v -o bin/go-enum .

Expand All @@ -23,24 +31,25 @@ test: generate gen-test
if [ ! -d coverage ]; then mkdir coverage; fi
go test -v ./generator -race -cover -coverprofile=$(COVERAGEDIR)/generator.coverprofile

cover:
cover: gen-test
go tool cover -html=$(COVERAGEDIR)/generator.coverprofile -o $(COVERAGEDIR)/generator.html

tc: test cover
coveralls:
gover $(COVERAGEDIR) $(COVERAGEDIR)/coveralls.coverprofile
goveralls -coverprofile=$(COVERAGEDIR)/coveralls.coverprofile -service=$(SERVICE) -repotoken=$(COVERALLS_TOKEN)

clean:
go clean
rm -f bin/go-enum
rm -rf coverage/

.PHONY: generate
generate:
go generate $$(glide nv)
go generate $(PACKAGES)

gen-test: build install
go generate $$(glide nv)
go generate $(PACKAGES)

install:
go install
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# go-enum
[![CircleCI](https://circleci.com/gh/abice/go-enum.svg?style=svg&circle-token=b44c10ce16bcef76e86da801d67811a5ff71fc72)](https://circleci.com/gh/abice/go-enum)
[![Go Report Card](https://goreportcard.com/badge/github.com/abice/go-enum)](https://goreportcard.com/report/github.com/abice/go-enum)

An enum generator for go


## How it works

The goal of go-enum is to create an easy to use enum generator that will take a decorated type declaration like `type EnumName int` and create the associated constant values and funcs that will make life a little easier for adding new values.
Expand Down
4 changes: 3 additions & 1 deletion generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ type Generator struct {
marshal bool
}

// Enum holds data for a discovered enum in the parsed source
type Enum struct {
Name string
Prefix string
Type string
Values []EnumValue
}

// EnumValue holds the individual data for each enum value within the found enum.
type EnumValue struct {
Name string
PrefixedName string
Expand Down Expand Up @@ -143,7 +145,7 @@ func (g *Generator) Generate(f *ast.File) ([]byte, error) {
"marshal": g.marshal,
}

err = g.t.ExecuteTemplate(vBuff, "enum", data)
g.t.ExecuteTemplate(vBuff, "enum", data)
}

formatted, err := imports.Process(pkg, vBuff.Bytes(), nil)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type rootT struct {
NoPrefix bool `cli:"noprefix" usage:"Prevents the constants generated from having the Enum as a prefix."`
Lowercase bool `cli:"lower" usage:"Adds lowercase variants of the enum strings for lookup."`
Marshal bool `cli:"marshal" usage:"Adds text marshalling functions."`
Prefix string `cli:"prefix" usage:"Replaces the prefix with a user one."`
}

func main() {
Expand Down

0 comments on commit 5edf28f

Please sign in to comment.