From 38d59d447932375cc11f91b09ffff71498eaf32e Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Tue, 6 Aug 2024 05:15:45 +0800 Subject: Feat: support extended text format with prefix & suffix in line as output Output plaintext CIDR with prefix and suffix in one line by using `text` format as output, specified by args `addPrefixInLine` and `addSuffixInLine` --- plugin/plaintext/common_out.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'plugin/plaintext') diff --git a/plugin/plaintext/common_out.go b/plugin/plaintext/common_out.go index ff4ab63b..cb38345d 100644 --- a/plugin/plaintext/common_out.go +++ b/plugin/plaintext/common_out.go @@ -25,6 +25,9 @@ type textOut struct { OutputDir string Want []string OnlyIPType lib.IPType + + AddPrefixInLine string + AddSuffixInLine string } func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.OutputConverter, error) { @@ -32,6 +35,9 @@ func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.Outp 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 { @@ -60,6 +66,9 @@ func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.Outp OutputDir: tmp.OutputDir, Want: tmp.Want, OnlyIPType: tmp.OnlyIPType, + + AddPrefixInLine: tmp.AddPrefixInLine, + AddSuffixInLine: tmp.AddSuffixInLine, }, nil } @@ -101,7 +110,13 @@ func (t *textOut) marshalBytes(entry *lib.Entry) ([]byte, error) { func (t *textOut) marshalBytesForTextOut(buf *bytes.Buffer, entryCidr []string) error { for _, cidr := range entryCidr { + if t.AddPrefixInLine != "" { + buf.WriteString(t.AddPrefixInLine) + } buf.WriteString(cidr) + if t.AddSuffixInLine != "" { + buf.WriteString(t.AddSuffixInLine) + } buf.WriteString("\n") } return nil @@ -149,6 +164,9 @@ func (t *textOut) marshalBytesForSurgeRuleSetOut(buf *bytes.Buffer, entryCidr [] buf.WriteString("IP-CIDR6,") } buf.WriteString(cidr) + if t.AddSuffixInLine != "" { + buf.WriteString(t.AddSuffixInLine) + } buf.WriteString("\n") } -- cgit v1.3.1