Files
claudia-docs-cli/internal/output/output.go
Claudia CLI Bot aca95d90f3 Initial MVP implementation of Claudia Docs CLI
- Auth commands: login, logout, status
- Document commands: create, list, get, update, delete
- Project commands: list, get
- Folder commands: list, create
- Tag commands: list, create, add
- Search command
- Reasoning save command
- JSON output format with --output text option
- Viper-based configuration management
- Cobra CLI framework
2026-03-31 01:25:15 +00:00

83 lines
1.7 KiB
Go

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
}
}