Skip to content

Commit

Permalink
Merge pull request #91 from yoheimuta/output-version
Browse files Browse the repository at this point in the history
feat: Add a version command
  • Loading branch information
yoheimuta authored Nov 12, 2019
2 parents 648f69c + fd94928 commit 8bf4c69
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ builds:
- windows
- darwin
- linux
ldflags:
- -s -w -X github.com/yoheimuta/protolint/internal/cmd.version={{.Version}} -X github.com/yoheimuta/protolint/internal/cmd.revision={{.ShortCommit}}
archive:
replacements:
darwin: Darwin
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ run/cmd/protolint/exampleconfig:

## build/cmd/protolint builds protolint
build/cmd/protolint:
go build -o protolint cmd/protolint/main.go
go build \
-ldflags "-X github.com/yoheimuta/protolint/internal/cmd.version=`git describe --tags --abbrev=0` -X github.com/yoheimuta/protolint/internal/cmd.revision=`git rev-parse --short HEAD`" \
-o protolint \
cmd/protolint/main.go

## build/example/plugin builds a plugin
build/example/plugin:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protolint lint -v . # with verbose output to investigate
protolint lint -reporter junit . # output results in JUnit XML format
protolint lint -plugin ./my_custom_rule1 -plugin ./my_custom_rule2 . # run custom lint rules.
protolint list # list all current lint rules being used
protolint version # print protolint version
```

protolint does not require configuration by default, for the majority of projects it should work out of the box.
Expand Down
31 changes: 23 additions & 8 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ const (
Protocol Buffer Linter Command.
Usage:
protolint .
protolint lint .
protolint lint -fix .
protolint lint -v .
protolint lint example.proto example2.proto
protolint list
protolint <command> [arguments]
The commands are:
lint lint protocol buffer files
list list all current lint rules being used
version print protolint version
`
)

const (
subCmdLint = "lint"
subCmdList = "list"
subCmdLint = "lint"
subCmdList = "list"
subCmdVersion = "version"
)

var (
version = "master"
revision = "latest"
)

// Do runs the command logic.
Expand Down Expand Up @@ -57,6 +63,8 @@ func doSub(
return doLint(args[1:], stdout, stderr)
case subCmdList:
return doList(stdout, stderr)
case subCmdVersion:
return doVersion(stdout)
default:
return doLint(args, stdout, stderr)
}
Expand Down Expand Up @@ -106,3 +114,10 @@ func doList(
)
return subCmd.Run()
}

func doVersion(
stdout io.Writer,
) osutil.ExitCode {
_, _ = fmt.Fprintln(stdout, "protolint version "+version+"("+revision+")")
return osutil.ExitSuccess
}

0 comments on commit 8bf4c69

Please sign in to comment.