1 Commits

Author SHA1 Message Date
7fc3bc7890 fix: table format rendering 2025-07-24 21:23:48 +02:00
4 changed files with 20 additions and 21 deletions

View File

@ -1,11 +1,8 @@
package cmd package cmd
const DefaultRequestTimeout uint = 30
type AppConfig struct { type AppConfig struct {
OutputVerbose bool OutputVerbose bool
OutputFormatter string OutputFormatter string
OutputOrderReverse bool OutputOrderReverse bool
PrintConfig bool PrintConfig bool
RequestTimeoutSeconds uint
} }

View File

@ -34,7 +34,6 @@ func initRootCmd() {
rootCmd.PersistentFlags().StringVarP(&appConfig.OutputFormatter, "output", "o", "table", "Set output format") rootCmd.PersistentFlags().StringVarP(&appConfig.OutputFormatter, "output", "o", "table", "Set output format")
rootCmd.PersistentFlags().BoolVar(&appConfig.OutputOrderReverse, "reverse", false, "Reverses output item order") rootCmd.PersistentFlags().BoolVar(&appConfig.OutputOrderReverse, "reverse", false, "Reverses output item order")
rootCmd.PersistentFlags().BoolVar(&appConfig.PrintConfig, "print-config", false, "Enable printing the application config") rootCmd.PersistentFlags().BoolVar(&appConfig.PrintConfig, "print-config", false, "Enable printing the application config")
rootCmd.PersistentFlags().UintVar(&appConfig.RequestTimeoutSeconds, "timeout", DefaultRequestTimeout, "Set the request timeout in seconds")
logger := jlog.New(slog.LevelDebug) logger := jlog.New(slog.LevelDebug)
ctx := jlog.ContextWith(context.Background(), logger) ctx := jlog.ContextWith(context.Background(), logger)

View File

@ -8,7 +8,6 @@ import (
"os" "os"
"slices" "slices"
"strings" "strings"
"time"
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces" "git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces"
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces/params" "git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces/params"
@ -93,8 +92,6 @@ func getVerbs(ctx context.Context, config *AppConfig) (commands []*cobra.Command
} }
logger := jlog.New(logLevel) logger := jlog.New(logLevel)
ctx := jlog.ContextWith(context.Background(), logger) ctx := jlog.ContextWith(context.Background(), logger)
ctx, cancel := context.WithTimeout(ctx, time.Duration(config.RequestTimeoutSeconds)*time.Second)
defer cancel()
// Print config // Print config
if config.PrintConfig { if config.PrintConfig {

View File

@ -41,7 +41,6 @@ func (f *TableFormatter) Format(list *interfaces.ResourceList) (io.Reader, error
// Setup table // Setup table
t := table.NewWriter() t := table.NewWriter()
t.SetOutputMirror(outputBuffer)
t.SetStyle(table.StyleLight) t.SetStyle(table.StyleLight)
// Write header // Write header
@ -66,15 +65,22 @@ func (f *TableFormatter) Format(list *interfaces.ResourceList) (io.Reader, error
} }
// Render // Render
output := func() string {
switch f.RenderFormat { switch f.RenderFormat {
case tableFormatCSV: case tableFormatCSV:
t.RenderCSV() return t.RenderCSV()
case tableFormatHTML: case tableFormatHTML:
t.RenderHTML() return t.RenderHTML()
case tableFormatMarkdown: case tableFormatMarkdown:
t.RenderMarkdown() return t.RenderMarkdown()
default: default:
t.Render() return t.Render()
}
}()
_, err := outputBuffer.WriteString(output)
if err != nil {
return nil, fmt.Errorf("failed to write rendered table: %w", err)
} }
return outputBuffer, nil return outputBuffer, nil