Skip to content

Commit

Permalink
add version file along with build/install Makefile targets
Browse files Browse the repository at this point in the history
also moved the gherkinfmt command into ./cmd/ subfolder
  • Loading branch information
muhqu committed Apr 10, 2014
1 parent 8252f28 commit a167881
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.out
gherkinfmt/gherkinfmt
cmd/gherkinfmt/gherkinfmt
23 changes: 19 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

default: gherkin.peg.go
default: build

.PHONY: default clean test integration get-deps
GIT_VERSION=$(shell git describe HEAD 2>/dev/null || git describe --tags HEAD)

.PHONY: default version clean build test install integration get-deps

peg=$(shell which peg \
|| ([ -x $(GOPATH)/bin/peg ] && echo $(GOPATH)/bin/peg) \
Expand Down Expand Up @@ -34,10 +36,23 @@ gherkin.peg.go: gherkin.peg
> $@
rm gherkin.peg.pp gherkin.peg.pp.go

test: gherkin.peg.go
go test ./ ./*/
version:
@echo "version: $(GIT_VERSION)" >&2
@cat version.go | sed -e 's/\(VERSION = "\)[^\"]*\("\)/\1'$(GIT_VERSION)'\2/' > version.go.tmp
@diff version.go.tmp version.go || (cat version.go.tmp > version.go)
@rm version.go.tmp

build: version gherkin.peg.go
go build ./ ./formater ./cmd/gherkinfmt

install: version gherkin.peg.go
go install ./cmd/gherkinfmt

test: version gherkin.peg.go
go test ./ ./formater ./cmd/gherkinfmt

integration: get-deps clean test
@echo "done: $(GIT_VERSION)" >&2

clean:
- rm gherkin.peg.go
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,29 @@ Read the [Documentation][godoc] over at [godoc.org][godoc].

Install
-------

### Via Go Get

```bash
make get-deps
make
make test
$ go get github.com/muhqu/go-gherkin
...
$ go install github.com/muhqu/go-gherkin/cmd/gherkinfmt
...
$ gherkinfmt -version # verify install
```

### Via GNU Make

```bash
$ git clone https://github.com/muhqu/go-gherkin
...
$ cd go-gherkin/
$ make get-deps build test install
...
$ gherkinfmt -version # verify install
```


Usage Example
-------------
```go
Expand Down
37 changes: 30 additions & 7 deletions gherkinfmt/gherkinfmt.go → cmd/gherkinfmt/gherkinfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Usage
-in PATH path to input file, defaults to stdin
-out PATH path to output file, defaults to stdout
Misc Options
-version version: ...
-help this help
Examples
$ gherkinfmt -in path/to/some.feature
Expand All @@ -32,6 +36,7 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path"

Expand All @@ -50,12 +55,13 @@ var skipComments bool
var noCommentAlign bool
var commentAlignMinIndent int
var verbose bool
var runVersion bool
var inputPath string
var inputReader io.Reader
var outputPath string
var outputWriter io.Writer

func initFlags() {
func init() {
flag.Usage = func() {
self := path.Base(os.Args[0])
fmt.Fprintf(os.Stderr, `Usage: %[1]s OPTIONS
Expand All @@ -73,13 +79,17 @@ IO Options
-out PATH path to output file, defaults to stdout
-v more verbose error messages
Misc Options
-version version: %[2]s
-help this help
Examples:
$ %[1]s -in path/to/some.feature
$ cat path/to/some.feature | %[1]s -centersteps
`, self)
`, self, gherkin.VERSION)
}
flag.BoolVar(&colorsYes, "color", false, "explicitly enable colors")
flag.BoolVar(&colorsNo, "nocolor", false, "explicitly disable colors")
Expand All @@ -91,7 +101,13 @@ Examples:
flag.BoolVar(&verbose, "v", false, "more verbose error messages")
flag.StringVar(&inputPath, "in", "", "path to input file")
flag.StringVar(&outputPath, "out", "", "path to output file")
flag.BoolVar(&runVersion, "version", false, "version: "+gherkin.VERSION)
flag.Parse()

if !verbose {
log.SetOutput(ioutil.Discard)
}
log.Print("Initialized")
}

func usageErr(err error) {
Expand All @@ -107,8 +123,10 @@ func usageErrWithVerboseHint(err error) {
}

func main() {
initFlags()

if runVersion {
fmt.Fprintf(os.Stdout, "%s\n", gherkin.VERSION)
return
}
if inputPath != "" {
inputReader, err = os.Open(inputPath)
if err != nil {
Expand Down Expand Up @@ -149,11 +167,16 @@ func main() {
}

fmtr := &formater.GherkinPrettyFormater{
AnsiColors: colors,
CenterSteps: centerSteps,
SkipSteps: skipSteps,
AnsiColors: colors,
CenterSteps: centerSteps,
SkipSteps: skipSteps,
SkipComments: skipComments,
NoAlignComments: noCommentAlign,
AlignCommentsMinIndent: commentAlignMinIndent,
}

log.Printf("Formater Settings: %+v", fmtr)

bytes, _ := ioutil.ReadAll(inputReader)
content := string(bytes)
gp := gherkin.NewGherkinDOMParser(content)
Expand Down
3 changes: 3 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package gherkin

const VERSION = "v0.1.0"

0 comments on commit a167881

Please # to comment.