package output import ( "encoding/json" "fmt" "os" "github.com/claudia/docs-cli/pkg/types" ) // Formatter handles output formatting type Formatter struct { Command string Server string } // NewFormatter creates a new formatter func NewFormatter(command, server string) *Formatter { return &Formatter{ Command: command, Server: server, } } // Success returns a success response func (f *Formatter) Success(data interface{}, durationMs int64) types.Response { return types.Response{ Success: true, Data: data, Meta: types.MetaInfo{ Command: f.Command, DurationMs: durationMs, Server: f.Server, }, } } // Error returns an error response func (f *Formatter) Error(code, message string, durationMs int64) types.Response { return types.Response{ Success: false, Error: &types.ErrorInfo{ Code: code, Message: message, }, Meta: types.MetaInfo{ Command: f.Command, DurationMs: durationMs, Server: f.Server, }, } } // PrintJSON prints the response as JSON func PrintJSON(resp types.Response) { enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") _ = enc.Encode(resp) } // PrintJSONCompact prints the response as compact JSON func PrintJSONCompact(resp types.Response) { enc := json.NewEncoder(os.Stdout) _ = enc.Encode(resp) } // PrintText prints a human-readable message func PrintText(message string) { fmt.Println(message) } // PrintError prints a human-readable error func PrintError(message string) { fmt.Fprintf(os.Stderr, "Error: %s\n", message) } // MeasureDuration returns a function to measure duration func MeasureDuration() (int64, func()) { return int64(0), func() { // Duration is calculated where needed } }