colorization support and redirect stdout and stderr for the command
Этот коммит содержится в:
родитель
17a24204da
коммит
ed9d322492
4 изменённых файлов: 90 добавлений и 12 удалений
|
@ -1,15 +1,19 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/DATA-DOG/godog"
|
"github.com/DATA-DOG/godog"
|
||||||
|
"github.com/shiena/ansicolor"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// will support Ansi colors for windows
|
||||||
|
stdout := ansicolor.NewAnsiColorWriter(os.Stdout)
|
||||||
|
stderr := ansicolor.NewAnsiColorWriter(os.Stdout)
|
||||||
|
|
||||||
builtFile := os.TempDir() + "/godog_build.go"
|
builtFile := os.TempDir() + "/godog_build.go"
|
||||||
if err := os.Remove(builtFile); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(builtFile); err != nil && !os.IsNotExist(err) {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -30,10 +34,12 @@ func main() {
|
||||||
}
|
}
|
||||||
w.Close()
|
w.Close()
|
||||||
|
|
||||||
cmd := strings.TrimSpace("go run " + builtFile + " " + strings.Join(os.Args[1:], " "))
|
c := strings.TrimSpace("go run " + builtFile + " " + strings.Join(os.Args[1:], " "))
|
||||||
out, err := exec.Command("sh", "-c", cmd).CombinedOutput()
|
cmd := exec.Command("sh", "-c", c)
|
||||||
|
cmd.Stdout = stdout
|
||||||
|
cmd.Stderr = stderr
|
||||||
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Println("output:", string(out))
|
|
||||||
}
|
}
|
||||||
|
|
20
colors.go
Обычный файл
20
colors.go
Обычный файл
|
@ -0,0 +1,20 @@
|
||||||
|
package godog
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type color int
|
||||||
|
|
||||||
|
const (
|
||||||
|
black color = iota + 30
|
||||||
|
red
|
||||||
|
green
|
||||||
|
yellow
|
||||||
|
blue
|
||||||
|
magenta
|
||||||
|
cyan
|
||||||
|
white
|
||||||
|
)
|
||||||
|
|
||||||
|
func cl(s string, c color) string {
|
||||||
|
return fmt.Sprintf("\033[%dm%s\033[0m", c, s)
|
||||||
|
}
|
53
config.go
Обычный файл
53
config.go
Обычный файл
|
@ -0,0 +1,53 @@
|
||||||
|
package godog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/DATA-DOG/godog/gherkin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cfg config
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
featuresPath string
|
||||||
|
formatterName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.StringVar(&cfg.featuresPath, "features", "features", "Path to feature files")
|
||||||
|
flag.StringVar(&cfg.formatterName, "formatter", "pretty", "Formatter name")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c config) validate() error {
|
||||||
|
inf, err := os.Stat(c.featuresPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !inf.IsDir() {
|
||||||
|
return fmt.Errorf("feature path \"%s\" is not a directory.", c.featuresPath)
|
||||||
|
}
|
||||||
|
switch c.formatterName {
|
||||||
|
case "pretty":
|
||||||
|
// ok
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Unsupported formatter name: %s", c.formatterName)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c config) features() (lst []*gherkin.Feature, err error) {
|
||||||
|
return lst, filepath.Walk(cfg.featuresPath, func(p string, f os.FileInfo, err error) error {
|
||||||
|
if err == nil && !f.IsDir() && strings.HasSuffix(p, ".feature") {
|
||||||
|
ft, err := gherkin.Parse(p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
lst = append(lst, ft)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
15
runner.go
15
runner.go
|
@ -1,15 +1,14 @@
|
||||||
package godog
|
package godog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Run() error {
|
func Run() {
|
||||||
log.Println("running godoc, num registered steps:", len(stepHandlers), "color test:", red("red"))
|
if !flag.Parsed() {
|
||||||
return nil
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
log.Println("running godoc, num registered steps:", len(stepHandlers), "color test:", cl("red", red))
|
||||||
func red(s string) string {
|
log.Println("will read features in path:", cl(cfg.featuresPath, yellow))
|
||||||
return fmt.Sprintf("\033[31m%s\033[0m", s)
|
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче