提交 55e0e8aa 编写于 作者: martianzhang's avatar martianzhang

fix #4 windows user compatiable

上级 75190193
......@@ -115,9 +115,9 @@ func init() {
"OK": {
Item: "OK",
Severity: "L0",
Summary: "✔️", // heavy check mark unicode
Content: `✔️`,
Case: "✔️",
Summary: "OK",
Content: `OK`,
Case: "OK",
Func: (*Query4Audit).RuleOK,
},
"ALI.001": {
......
......@@ -26,6 +26,7 @@ import (
"io/ioutil"
"os"
"regexp"
"runtime"
"strings"
"gopkg.in/yaml.v2"
......@@ -120,6 +121,14 @@ type Configration struct {
MaxPrettySQLLength int `yaml:"max-pretty-sql-length"` // 超出该长度的SQL会转换成指纹输出
}
// getDefaultLogOutput get default log-output by runtime.GOOS
func getDefaultLogOutput() string {
if runtime.GOOS == "windows" {
return "nul"
}
return os.Stderr.Name()
}
// Config 默认设置
var Config = &Configration{
OnlineDSN: &dsn{
......@@ -158,7 +167,7 @@ var Config = &Configration{
SpaghettiQueryLength: 2048,
AllowDropIndex: false,
LogLevel: 3,
LogOutput: os.Stderr.Name(),
LogOutput: getDefaultLogOutput(),
ReportType: "markdown",
ReportCSS: "",
ReportJavascript: "",
......@@ -538,7 +547,7 @@ func readCmdFlags() error {
maxPrettySQLLength := flag.Int("max-pretty-sql-length", Config.MaxPrettySQLLength, "MaxPrettySQLLength, 超出该长度的SQL会转换成指纹输出")
// 一个不存在log-level,用于更新usage。
// 因为vitess里面也用了flag,这些vitess的参数我们不需要关注
if !Config.Verbose {
if !Config.Verbose && runtime.GOOS != "windows" {
flag.Usage = usage
}
flag.Parse()
......@@ -570,7 +579,11 @@ func readCmdFlags() error {
if BaseDir == "" {
Config.LogOutput = *logOutput
} else {
Config.LogOutput = BaseDir + "/" + *logOutput
if runtime.GOOS == "windows" {
Config.LogOutput = *logOutput
} else {
Config.LogOutput = BaseDir + "/" + *logOutput
}
}
}
Config.ReportType = strings.ToLower(*reportType)
......
......@@ -18,6 +18,7 @@ package common
import (
"flag"
"runtime"
"testing"
"github.com/kr/pretty"
......@@ -25,6 +26,17 @@ import (
var update = flag.Bool("update", false, "update .golden files")
func TestGetDefaultLogOutput(t *testing.T) {
output := getDefaultLogOutput()
if runtime.GOOS == "windows" && output != "nul" {
t.Error("windows default -log-output not nul")
}
if runtime.GOOS != "windows" && output != "/dev/stderr" {
t.Error("default -log-output not /dev/stderr")
}
}
func TestParseConfig(t *testing.T) {
err := ParseConfig("")
if err != nil {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册