-F新增从stdin中读, 并添加颜色参数

This commit is contained in:
M09Ic 2023-02-08 19:17:42 +08:00
parent 5ace37824a
commit 25188b24e8
2 changed files with 16 additions and 4 deletions

View File

@ -50,7 +50,7 @@ func Spray() {
}
if option.Format != "" {
internal.Format(option.Format)
internal.Format(option.Format, !option.NoColor)
os.Exit(0)
}

View File

@ -6,10 +6,18 @@ import (
"github.com/chainreactors/logs"
"github.com/chainreactors/spray/pkg"
"io/ioutil"
"os"
)
func Format(filename string) {
content, err := ioutil.ReadFile(filename)
func Format(filename string, color bool) {
var content []byte
var err error
if filename == "stdin" {
content, err = ioutil.ReadAll(os.Stdin)
} else {
content, err = ioutil.ReadFile(filename)
}
if err != nil {
return
}
@ -24,6 +32,10 @@ func Format(filename string) {
results = append(results, &result)
}
for _, result := range results {
logs.Log.Info(result.String())
if color {
logs.Log.Info(result.ColorString())
} else {
logs.Log.Info(result.String())
}
}
}