@@ -174,6 +174,7 @@ func NewTable[T any](out io.Writer) *Table[T] {
174174 fieldMapping : map [string ]FieldFn [T ]{},
175175 fieldAlias : map [string ]string {},
176176 allowedFields : map [string ]bool {},
177+ deprecations : map [string ]string {},
177178 }
178179}
179180
@@ -187,6 +188,7 @@ type Table[T any] struct {
187188 fieldMapping map [string ]FieldFn [T ]
188189 fieldAlias map [string ]string
189190 allowedFields map [string ]bool
191+ deprecations map [string ]string
190192}
191193
192194// Columns returns a list of known output columns.
@@ -212,6 +214,13 @@ func (o *Table[T]) AddFieldFn(field string, fn FieldFn[T]) *Table[T] {
212214 return o
213215}
214216
217+ // MarkFieldAsDeprecated marks the specified field as deprecated. The message will be printed
218+ // to stderr if the column is used.
219+ func (o * Table [T ]) MarkFieldAsDeprecated (field string , message string ) * Table [T ] {
220+ o .deprecations [field ] = message
221+ return o
222+ }
223+
215224// AddAllowedFields reads all first level fieldnames of the struct and allows them to be used.
216225func (o * Table [T ]) AddAllowedFields (obj T ) * Table [T ] {
217226 v := reflect .ValueOf (obj )
@@ -250,18 +259,21 @@ func (o *Table[T]) RemoveAllowedField(fields ...string) *Table[T] {
250259 return o
251260}
252261
253- // ValidateColumns returns an error if invalid columns are specified.
254- func (o * Table [T ]) ValidateColumns (cols []string ) error {
255- var invalidCols []string
262+ // ValidateColumns returns a list of warnings for the used columns and an error if invalid columns are specified.
263+ func (o * Table [T ]) ValidateColumns (cols []string ) ([] string , error ) {
264+ var warnings , invalidCols []string
256265 for _ , col := range cols {
266+ if warning , isDeprecated := o .deprecations [strings .ToLower (col )]; isDeprecated {
267+ warnings = append (warnings , warning )
268+ }
257269 if _ , ok := o .allowedFields [strings .ToLower (col )]; ! ok {
258270 invalidCols = append (invalidCols , col )
259271 }
260272 }
261273 if len (invalidCols ) > 0 {
262- return fmt .Errorf ("invalid table columns: %s" , strings .Join (invalidCols , "," ))
274+ return warnings , fmt .Errorf ("invalid table columns: %s" , strings .Join (invalidCols , "," ))
263275 }
264- return nil
276+ return warnings , nil
265277}
266278
267279// WriteHeader writes the table header.
0 commit comments