sq/cli/output/outputx/outputx.go
Neil O'Toole 6ca26f4e4f
Column rename: template now has Alpha field. (#285)
* wip: refactor col name mungeing

* Finished refactoring FieldMeta

* Renamed tpl .AlphaIndex to .Alpha

* wip: debugging source config override

* Source config override passing tests

* CHANGELOG update
2023-07-08 19:34:53 -06:00

40 lines
1.1 KiB
Go

// Package outputx contains extensions to pkg output, and helpers
// for implementing output writers.
//
// REVISIT: This package is a bit of an odd duck. Can the functionality
// be moved elsewhere?
package outputx
import (
"reflect"
"github.com/neilotoole/sq/libsq/core/options"
)
// VerboseOpt is a verbose realization of an options.Opt value.
// This is used primarily to print metadata about the opt.
type VerboseOpt struct {
Key string `json:"key"`
Usage string `json:"usage"`
Type string `json:"type"`
IsSet bool `json:"is_set"`
DefaultValue any `json:"default_value"`
Value any `json:"value"`
Help string `json:"help"`
}
// NewVerboseOpt returns a VerboseOpt built from opt and o.
func NewVerboseOpt(opt options.Opt, o options.Options) VerboseOpt {
v := VerboseOpt{
Key: opt.Key(),
Usage: opt.Usage(),
DefaultValue: opt.GetAny(nil),
IsSet: o.IsSet(opt),
Help: opt.Help(),
Value: opt.GetAny(o),
Type: reflect.TypeOf(opt.GetAny(nil)).String(),
}
return v
}