Skip to content

Commit

Permalink
Feat: support to add prefix & suffix to text output format
Browse files Browse the repository at this point in the history
  • Loading branch information
Loyalsoldier committed Aug 15, 2024
1 parent 40ce626 commit 41c6f52
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugin/plaintext/text_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func newTextOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, e
OutputDir string `json:"outputDir"`
Want []string `json:"wantedList"`
OnlyIPType lib.IPType `json:"onlyIPType"`

AddPrefixInLine string `json:"addPrefixInLine"`
AddSuffixInLine string `json:"addSuffixInLine"`
}

if len(data) > 0 {
Expand Down Expand Up @@ -62,6 +65,9 @@ func newTextOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, e
OutputDir: tmp.OutputDir,
Want: wantList,
OnlyIPType: tmp.OnlyIPType,

AddPrefixInLine: tmp.AddPrefixInLine,
AddSuffixInLine: tmp.AddSuffixInLine,
}, nil
}

Expand All @@ -72,6 +78,9 @@ type textOut struct {
OutputDir string
Want []string
OnlyIPType lib.IPType

AddPrefixInLine string
AddSuffixInLine string
}

func (t *textOut) GetType() string {
Expand Down Expand Up @@ -164,7 +173,13 @@ func (t *textOut) marshalText(entry *lib.Entry) ([]string, error) {
func (t *textOut) writeFile(filename string, cidrList []string) error {
var buf bytes.Buffer
for _, cidr := range cidrList {
if t.AddPrefixInLine != "" {
buf.WriteString(t.AddPrefixInLine)
}
buf.WriteString(cidr)
if t.AddSuffixInLine != "" {
buf.WriteString(t.AddSuffixInLine)
}
buf.WriteString("\n")
}
cidrBytes := buf.Bytes()
Expand Down

0 comments on commit 41c6f52

Please sign in to comment.