feat: output system — table/json/yaml/raw printers with struct tag driven tables

This commit is contained in:
2026-07-28 15:54:18 +08:00
parent 5a75b3e7cd
commit 03f089c9c3
7 changed files with 278 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
package output
import (
"fmt"
"io"
)
type Printer struct {
format string
writer io.Writer
}
func New(format string, w io.Writer) *Printer {
return &Printer{format: format, writer: w}
}
func (p *Printer) Print(data any) error {
switch p.format {
case "table":
return printTable(p.writer, data)
case "json":
return printJSON(p.writer, data)
case "yaml":
return printYAML(p.writer, data)
default:
return fmt.Errorf("unknown output format: %s", p.format)
}
}
func (p *Printer) PrintRaw(raw []byte) error {
_, err := fmt.Fprintln(p.writer, string(raw))
return err
}