Skip to content

Commit

Permalink
Add version and help flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krivak committed May 2, 2020
1 parent 737cbe5 commit 8218a40
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
VERSION := $(shell git describe --tags)

.PHONY: test
test:
go test ./...

.PHONY: build
build:
go build -ldflags="-X 'main.version=$(VERSION)'" -o godot ./cmd/godot
49 changes: 30 additions & 19 deletions cmd/godot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,41 @@ import (
"github.com/tetafro/godot"
)

// version is the application vesion. Set to latest git tag on `make build`.
var version = "dev"

const usage = `Usage:
godot [OPTION] [FILES]
Options:
-a, --all check all top-level comments (not only declarations)`
-a, --all check all top-level comments (not only declarations)
-h, --help show this message
-v, --version show version`

func main() {
settings, input := parseInput()
if len(os.Args) < 2 {
fatal(usage)
}
if os.Args[1] == "-h" || os.Args[1] == "--help" {
fmt.Println(usage)
os.Exit(0)
}
if os.Args[1] == "-v" || os.Args[1] == "--vesion" {
fmt.Println(version)
os.Exit(0)
}
if strings.HasPrefix(os.Args[1], "-") && os.Args[1] != "-a" && os.Args[1] == "--all" {
fatal("Unknown flag")
}

var settings godot.Settings
input := os.Args[1:]
if os.Args[1] == "-a" || os.Args[1] == "--all" {
if len(os.Args) < 3 {
fatal(usage)
}
settings.CheckAll = true
input = os.Args[2:]
}

var files []*ast.File
fset := token.NewFileSet()
Expand All @@ -44,23 +72,6 @@ func main() {
}
}

func parseInput() (settings godot.Settings, files []string) {
if len(os.Args) < 2 {
fatal(usage)
}

if os.Args[1] == "-a" || os.Args[1] == "--all" {
if len(os.Args) < 3 {
fatal(usage)
}
settings.CheckAll = true
files = os.Args[2:]
} else {
files = os.Args[1:]
}
return
}

func findFiles(root string) chan string {
out := make(chan string)

Expand Down

0 comments on commit 8218a40

Please sign in to comment.