88 "sort"
99 "strconv"
1010 "strings"
11+ "time"
1112
1213 "github.com/charmbracelet/lipgloss"
1314 "github.com/heygen-com/heygen-cli/internal/command"
@@ -98,7 +99,7 @@ func (f *HumanFormatter) renderTable(rows []map[string]any, columns []command.Co
9899
99100 for _ , row := range rows {
100101 for i , col := range columns {
101- cell := formatValue (fieldValue (row , col .Field ))
102+ cell := formatCell (fieldValue (row , col .Field ), col . Field )
102103 if w := lipgloss .Width (cell ); w > widths [i ] {
103104 widths [i ] = w
104105 }
@@ -111,7 +112,7 @@ func (f *HumanFormatter) renderTable(rows []map[string]any, columns []command.Co
111112 for _ , row := range rows {
112113 values := make ([]string , len (columns ))
113114 for i , col := range columns {
114- values [i ] = formatValue (fieldValue (row , col .Field ))
115+ values [i ] = formatCell (fieldValue (row , col .Field ), col . Field )
115116 }
116117 if _ , err := fmt .Fprintln (f .out , renderTableLine (values , widths , true )); err != nil {
117118 return err
@@ -159,7 +160,7 @@ func (f *HumanFormatter) renderKeyValue(obj map[string]any) error {
159160 for _ , key := range keys {
160161 label := humanizeKey (key )
161162 padding := strings .Repeat (" " , max (0 , maxLabelWidth - lipgloss .Width (label )))
162- if _ , err := fmt .Fprintf (f .out , "%s:%s %s\n " , label , padding , formatValue (obj [key ])); err != nil {
163+ if _ , err := fmt .Fprintf (f .out , "%s:%s %s\n " , label , padding , formatCell (obj [key ], key )); err != nil {
163164 return err
164165 }
165166 }
@@ -232,6 +233,18 @@ func fieldValue(row map[string]any, path string) any {
232233 return current
233234}
234235
236+ func formatCell (v any , fieldName string ) string {
237+ if value , ok := v .(float64 ); ok {
238+ if isUnixTimestamp (value ) {
239+ return time .Unix (int64 (value ), 0 ).UTC ().Format ("2006-01-02 15:04" )
240+ }
241+ if strings .Contains (strings .ToLower (fieldName ), "duration" ) {
242+ return formatDuration (value )
243+ }
244+ }
245+ return formatValue (v )
246+ }
247+
235248func formatValue (v any ) string {
236249 switch value := v .(type ) {
237250 case nil :
@@ -261,6 +274,24 @@ func formatValue(v any) string {
261274 }
262275}
263276
277+ func isUnixTimestamp (value float64 ) bool {
278+ if value != float64 (int64 (value )) {
279+ return false
280+ }
281+ return value > 1.5e9 && value < 2.2e9
282+ }
283+
284+ func formatDuration (seconds float64 ) string {
285+ d := time .Duration (seconds * float64 (time .Second ))
286+ if d < time .Minute {
287+ return fmt .Sprintf ("%ds" , int (d .Seconds ()))
288+ }
289+ if d < time .Hour {
290+ return fmt .Sprintf ("%dm %ds" , int (d .Minutes ()), int (d .Seconds ())% 60 )
291+ }
292+ return fmt .Sprintf ("%dh %dm %ds" , int (d .Hours ()), int (d .Minutes ())% 60 , int (d .Seconds ())% 60 )
293+ }
294+
264295func humanizeKey (key string ) string {
265296 parts := strings .FieldsFunc (key , func (r rune ) bool {
266297 return r == '_' || r == '-' || r == '.'
@@ -273,4 +304,3 @@ func humanizeKey(key string) string {
273304 }
274305 return strings .Join (parts , " " )
275306}
276-
0 commit comments