diff --git a/go.mod b/go.mod index a6ecc80..8731b14 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/chainreactors/files v0.0.0-20240716182835-7884ee1e77f0 github.com/chainreactors/fingers v0.0.0-20240716172449-2fc3147b9c2a github.com/chainreactors/logs v0.0.0-20240207121836-c946f072f81f - github.com/chainreactors/parsers v0.0.0-20240708072709-07deeece7ce2 + github.com/chainreactors/parsers v0.0.0-20240829055950-923f89a92b84 github.com/chainreactors/utils v0.0.0-20240805193040-ff3b97aa3c3f github.com/chainreactors/words v0.4.1-0.20240510105042-5ba5c2edc508 github.com/expr-lang/expr v1.16.9 diff --git a/go.sum b/go.sum index de351f2..d14c15a 100644 --- a/go.sum +++ b/go.sum @@ -93,6 +93,10 @@ github.com/chainreactors/logs v0.0.0-20240207121836-c946f072f81f/go.mod h1:6Mv6W github.com/chainreactors/parsers v0.0.0-20240702104902-1ce563b7ef76/go.mod h1:G/XLE5RAaUdqADkbhQ59mPrUAbsJLiQ2DN6CwtwNpBQ= github.com/chainreactors/parsers v0.0.0-20240708072709-07deeece7ce2 h1:sE3SChgHLtPsEaqHo5tDSy8niDys1SO174C4eHlShSw= github.com/chainreactors/parsers v0.0.0-20240708072709-07deeece7ce2/go.mod h1:7rXdYz6jrdjF0WUH1ICcAXKIKKjKmJo2PU8u43V7jkA= +github.com/chainreactors/parsers v0.0.0-20240825154421-240ad7eba29d h1:/rtYIkD9F1Va7YbAaHEPpLSOjsEEfqow6FKL/gcO5ns= +github.com/chainreactors/parsers v0.0.0-20240825154421-240ad7eba29d/go.mod h1:7rXdYz6jrdjF0WUH1ICcAXKIKKjKmJo2PU8u43V7jkA= +github.com/chainreactors/parsers v0.0.0-20240829055950-923f89a92b84 h1:F6umsdHLxKILxrH5wY2zVYwxMmb8XdCEc9apf7GWpOk= +github.com/chainreactors/parsers v0.0.0-20240829055950-923f89a92b84/go.mod h1:7rXdYz6jrdjF0WUH1ICcAXKIKKjKmJo2PU8u43V7jkA= github.com/chainreactors/utils v0.0.0-20240528085651-ba1b255482c1/go.mod h1:JA4eiQZm+7AsfjXBcIzIdVKBEhDCb16eNtWFCGTxlvs= github.com/chainreactors/utils v0.0.0-20240704062557-662d623b74f4/go.mod h1:JA4eiQZm+7AsfjXBcIzIdVKBEhDCb16eNtWFCGTxlvs= github.com/chainreactors/utils v0.0.0-20240715080349-d2d0484c95ed/go.mod h1:LajXuvESQwP+qCMAvlcoSXppQCjuLlBrnQpu9XQ1HtU= diff --git a/internal/option.go b/internal/option.go index bfddfad..6d1eb51 100644 --- a/internal/option.go +++ b/internal/option.go @@ -87,7 +87,8 @@ type OutputOptions struct { AutoFile bool `long:"auto-file" description:"Bool, auto generator output and fuzzy filename" config:"auto-file"` Format string `short:"F" long:"format" description:"String, output format, e.g.: --format 1.json" config:"format"` Json bool `short:"j" long:"json" description:"Bool, output json" config:"json"` - OutputProbe string `short:"o" long:"probe" description:"String, output format" config:"output_probe"` + FileOutput string `short:"O" long:"file-output" default:"json" description:"Bool, file output format" config:"file_output"` + OutputProbe string `short:"o" long:"probe" description:"String, output format" config:"output"` Quiet bool `short:"q" long:"quiet" description:"Bool, Quiet" config:"quiet"` NoColor bool `long:"no-color" description:"Bool, no color" config:"no-color"` NoBar bool `long:"no-bar" description:"Bool, No progress bar" config:"no-bar"` @@ -164,7 +165,6 @@ func (opt *Option) Validate() error { if opt.Depth > 0 && opt.ResumeFrom != "" { // 递归与断点续传会造成混淆, 断点续传的word与rule不是通过命令行获取的 - return errors.New("--resume and --depth cannot be used at the same time") } diff --git a/internal/runner.go b/internal/runner.go index dc6789e..efebf14 100644 --- a/internal/runner.go +++ b/internal/runner.go @@ -355,7 +355,7 @@ func (r *Runner) saveStat(content string) { func (r *Runner) Output(bl *pkg.Baseline) { var out string if r.Option.Json { - out = bl.Jsonify() + out = bl.ToJson() } else if len(r.Probes) > 0 { out = bl.Format(r.Probes) } else if r.Color { @@ -364,14 +364,20 @@ func (r *Runner) Output(bl *pkg.Baseline) { out = bl.String() } - if bl.IsFuzzy { - logs.Log.Console("[fuzzy] " + out + "\n") - } else { + if bl.IsValid { logs.Log.Console(out + "\n") + + } else if r.Fuzzy && bl.IsFuzzy { + logs.Log.Console("[fuzzy] " + out + "\n") } if r.OutputFile != nil { - r.OutputFile.SafeWrite(bl.Jsonify() + "\n") + if r.FileOutput == "json" { + r.OutputFile.SafeWrite(bl.ToJson() + "\n") + } else if r.FileOutput == "csv" { + r.OutputFile.SafeWrite(bl.ToCSV() + "\n") + } + r.OutputFile.SafeSync() } } @@ -385,7 +391,7 @@ func (r *Runner) OutputHandler() { return } if r.DumpFile != nil { - r.DumpFile.SafeWrite(bl.Jsonify() + "\n") + r.DumpFile.SafeWrite(bl.ToJson() + "\n") r.DumpFile.SafeSync() } if bl.IsValid { @@ -412,10 +418,8 @@ func (r *Runner) OutputHandler() { if !ok { return } - if r.Fuzzy { - r.Output(bl) - r.outwg.Done() - } + r.Output(bl) + r.outwg.Done() } } }()