summaryrefslogtreecommitdiff
path: root/plugin/plaintext/text_out.go
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-10-24 06:01:54 +0800
committerLoyalsoldier <[email protected]>2024-10-24 06:01:54 +0800
commit40e0ad6895d62ad12ea1b1da4293dbcc05ea1d29 (patch)
treea3b3310824baa53ff4d7dad417a90a769386269d /plugin/plaintext/text_out.go
parent4cf50641990c7df79b1a03438dd9273532182e2f (diff)
Feat: support to exclude specified lists when output
Diffstat (limited to 'plugin/plaintext/text_out.go')
-rw-r--r--plugin/plaintext/text_out.go83
1 files changed, 45 insertions, 38 deletions
diff --git a/plugin/plaintext/text_out.go b/plugin/plaintext/text_out.go
index dce92ce8..cc51da95 100644
--- a/plugin/plaintext/text_out.go
+++ b/plugin/plaintext/text_out.go
@@ -36,52 +36,59 @@ func (t *textOut) GetDescription() string {
}
func (t *textOut) Output(container lib.Container) error {
- switch len(t.Want) {
- case 0:
- list := make([]string, 0, 300)
- for entry := range container.Loop() {
- list = append(list, entry.GetName())
+ for _, name := range t.filterAndSortList(container) {
+ entry, found := container.GetEntry(name)
+ if !found {
+ log.Printf("❌ entry %s not found\n", name)
+ continue
}
- // Sort the list
- slices.Sort(list)
+ data, err := t.marshalBytes(entry)
+ if err != nil {
+ return err
+ }
- for _, name := range list {
- entry, found := container.GetEntry(name)
- if !found {
- log.Printf("❌ entry %s not found", name)
- continue
- }
- data, err := t.marshalBytes(entry)
- if err != nil {
- return err
- }
- filename := strings.ToLower(entry.GetName()) + t.OutputExt
- if err := t.writeFile(filename, data); err != nil {
- return err
- }
+ filename := strings.ToLower(entry.GetName()) + t.OutputExt
+ if err := t.writeFile(filename, data); err != nil {
+ return err
}
+ }
+
+ return nil
+}
- default:
+func (t *textOut) filterAndSortList(container lib.Container) []string {
+ excludeMap := make(map[string]bool)
+ for _, exclude := range t.Exclude {
+ if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" {
+ excludeMap[exclude] = true
+ }
+ }
+
+ wantList := make([]string, 0, len(t.Want))
+ for _, want := range t.Want {
+ if want = strings.ToUpper(strings.TrimSpace(want)); want != "" && !excludeMap[want] {
+ wantList = append(wantList, want)
+ }
+ }
+
+ if len(wantList) > 0 {
// Sort the list
- slices.Sort(t.Want)
+ slices.Sort(wantList)
+ return wantList
+ }
- for _, name := range t.Want {
- entry, found := container.GetEntry(name)
- if !found {
- log.Printf("❌ entry %s not found", name)
- continue
- }
- data, err := t.marshalBytes(entry)
- if err != nil {
- return err
- }
- filename := strings.ToLower(entry.GetName()) + t.OutputExt
- if err := t.writeFile(filename, data); err != nil {
- return err
- }
+ list := make([]string, 0, 300)
+ for entry := range container.Loop() {
+ name := entry.GetName()
+ if excludeMap[name] {
+ continue
}
+ list = append(list, name)
}
- return nil
+ // Sort the list
+ slices.Sort(list)
+
+ return list
}