Skip to content

Commit

Permalink
Feat: support to customize output file extension in all plaintext for…
Browse files Browse the repository at this point in the history
…mats
  • Loading branch information
Loyalsoldier committed Aug 6, 2024
1 parent fa11a12 commit ee2fd80
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
20 changes: 20 additions & 0 deletions config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@
"addPrefixInLine": "deny from "
}
},
{
"type": "text",
"action": "output",
"args": {
"outputDir": "./output/nginx/allow",
"outputExtension": ".conf",
"addPrefixInLine": "allow ",
"addSuffixInLine": ";"
}
},
{
"type": "text",
"action": "output",
"args": {
"outputDir": "./output/nginx/deny",
"outputExtension": ".conf",
"addPrefixInLine": "deny ",
"addSuffixInLine": ";"
}
},
{
"type": "stdout",
"action": "output"
Expand Down
7 changes: 7 additions & 0 deletions plugin/plaintext/common_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type textOut struct {
Action lib.Action
Description string
OutputDir string
OutputExt string
Want []string
OnlyIPType lib.IPType

Expand All @@ -33,6 +34,7 @@ type textOut struct {
func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
var tmp struct {
OutputDir string `json:"outputDir"`
OutputExt string `json:"outputExtension"`
Want []string `json:"wantedList"`
OnlyIPType lib.IPType `json:"onlyIPType"`

Expand All @@ -59,11 +61,16 @@ func newTextOut(iType string, action lib.Action, data json.RawMessage) (lib.Outp
}
}

if tmp.OutputExt == "" {
tmp.OutputExt = ".txt"
}

return &textOut{
Type: iType,
Action: action,
Description: descTextOut,
OutputDir: tmp.OutputDir,
OutputExt: tmp.OutputExt,
Want: tmp.Want,
OnlyIPType: tmp.OnlyIPType,

Expand Down
4 changes: 2 additions & 2 deletions plugin/plaintext/text_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (t *textOut) Output(container lib.Container) error {
if err != nil {
return err
}
filename := strings.ToLower(entry.GetName()) + ".txt"
filename := strings.ToLower(entry.GetName()) + t.OutputExt
if err := t.writeFile(filename, data); err != nil {
return err
}
Expand All @@ -67,7 +67,7 @@ func (t *textOut) Output(container lib.Container) error {
if err != nil {
return err
}
filename := strings.ToLower(entry.GetName()) + ".txt"
filename := strings.ToLower(entry.GetName()) + t.OutputExt
if err := t.writeFile(filename, data); err != nil {
return err
}
Expand Down

0 comments on commit ee2fd80

Please sign in to comment.