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

fix #4 windows user compatiable

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