parse flags in runner command, to be able to show version or help, closes #34

Этот коммит содержится в:
gedi 2016-06-01 13:47:34 +03:00
родитель f9eab9da27
коммит 9bde6a2b9b
6 изменённых файлов: 33 добавлений и 9 удалений

Просмотреть файл

@ -157,6 +157,10 @@ See implementation examples:
### Changes
**2016-06-01**
- parse flags in main command, to show version and help without needing
to compile test package and buildable go sources.
**2016-05-28**
- show nicely formatted called step func name and file path

Просмотреть файл

@ -17,11 +17,11 @@ import (
var statusMatch = regexp.MustCompile("^exit status (\\d+)")
var parsedStatus int
var stdout = createAnsiColorWriter(os.Stdout)
var stderr = createAnsiColorWriter(statusOutputFilter(os.Stderr))
func buildAndRun() (int, error) {
var status int
// will support Ansi colors for windows
stdout := createAnsiColorWriter(os.Stdout)
stderr := createAnsiColorWriter(statusOutputFilter(os.Stderr))
dir := fmt.Sprintf(filepath.Join("%s", "godog-%d"), os.TempDir(), time.Now().UnixNano())
err := godog.Build(dir)
@ -75,9 +75,25 @@ func buildAndRun() (int, error) {
}
func main() {
var vers, defs, sof bool
var tags, format string
var concurrency int
flagSet := godog.FlagSet(&format, &tags, &defs, &sof, &vers, &concurrency)
err := flagSet.Parse(os.Args[1:])
if err != nil {
fmt.Fprintln(stderr, err)
os.Exit(1)
}
if vers {
fmt.Fprintln(stdout, "Godog version is", godog.Version)
os.Exit(0) // should it be 0?
}
status, err := buildAndRun()
if err != nil {
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(stderr, err)
os.Exit(1)
}
// it might be a case, that status might not be resolved

Просмотреть файл

@ -20,6 +20,6 @@ Feature: get version
And the response should match json:
"""
{
"version": "v0.4.2"
"version": "v0.4.3"
}
"""

Просмотреть файл

@ -5,7 +5,8 @@ import (
"fmt"
)
func flags(format, tags *string, defs, sof, vers *bool, cl *int) *flag.FlagSet {
// FlagSet allows to manage flags by external suite runner
func FlagSet(format, tags *string, defs, sof, vers *bool, cl *int) *flag.FlagSet {
set := flag.NewFlagSet("godog", flag.ExitOnError)
set.StringVar(format, "format", "pretty", "")
set.StringVar(format, "f", "pretty", "")
@ -32,7 +33,10 @@ func usage() {
// --- GENERAL ---
fmt.Println(cl("Usage:", yellow))
fmt.Println(s(2) + "godog [options] [<features>]\n")
fmt.Printf(s(2) + "godog [options] [<features>]\n\n")
// description
fmt.Println("Builds a test package and runs given feature files.")
fmt.Printf("Command should be run from the directory of tested package and contain buildable go source.\n\n")
// --- ARGUMENTS ---
fmt.Println(cl("Arguments:", yellow))

Просмотреть файл

@ -44,4 +44,4 @@ Godog was inspired by Behat and the above description is taken from it's documen
package godog
// Version of package - based on Semantic Versioning 2.0.0 http://semver.org/
const Version = "v0.4.2"
const Version = "v0.4.3"

2
run.go
Просмотреть файл

@ -56,7 +56,7 @@ func Run(contextInitializer func(suite *Suite)) int {
var vers, defs, sof bool
var tags, format string
var concurrency int
flagSet := flags(&format, &tags, &defs, &sof, &vers, &concurrency)
flagSet := FlagSet(&format, &tags, &defs, &sof, &vers, &concurrency)
err := flagSet.Parse(os.Args[1:])
fatal(err)