feat: add name formatter #10

Open
bissendorf wants to merge 3 commits from feat/output-name into dev
2 changed files with 22 additions and 0 deletions
Showing only changes of commit 79c6a1ea8a - Show all commits

View File

@ -12,4 +12,5 @@ var Formatters = map[string]interfaces.Formatter{
"csv": &TableFormatter{HideSummary: true, RenderFormat: tableFormatCSV}, "csv": &TableFormatter{HideSummary: true, RenderFormat: tableFormatCSV},
"html": &TableFormatter{HideSummary: true, RenderFormat: tableFormatHTML}, "html": &TableFormatter{HideSummary: true, RenderFormat: tableFormatHTML},
"markdown": &TableFormatter{HideSummary: true, RenderFormat: tableFormatMarkdown}, "markdown": &TableFormatter{HideSummary: true, RenderFormat: tableFormatMarkdown},
"name": &NameFormatter{},
} }

21
core/output/name.go Normal file
View File

@ -0,0 +1,21 @@
package output
import (
"bytes"
"io"
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces"
)
type NameFormatter struct{}
func (f *NameFormatter) Format(list *interfaces.ResourceList) (io.Reader, error) {
var buffer = make([]byte, 0, 1024)
outputBuffer := bytes.NewBuffer(buffer)
for _, item := range list.Items {
outputBuffer.WriteString(item.ItemName() + "\r\n")
}
return outputBuffer, nil
}