feat(list): default to no borders, and no header; adds TSV output
This commit is contained in:
parent
a4930b781e
commit
885ef5ce4f
2 changed files with 16 additions and 8 deletions
12
cmd/list.go
12
cmd/list.go
|
|
@ -69,7 +69,13 @@ func list(cmd *cobra.Command, args []string) error {
|
|||
output := cmd.OutOrStdout()
|
||||
tw := table.NewWriter()
|
||||
tw.SetOutputMirror(output)
|
||||
tw.SetStyle(table.StyleLight)
|
||||
tw.SetStyle(table.StyleDefault)
|
||||
// Should these be settable flags?
|
||||
tw.Style().Options.SeparateHeader = false
|
||||
tw.Style().Options.SeparateFooter = false
|
||||
tw.Style().Options.DrawBorder = false
|
||||
tw.Style().Options.SeparateRows = false
|
||||
tw.Style().Options.SeparateColumns = false
|
||||
|
||||
var maxContentWidths []int
|
||||
maxContentWidths = make([]int, len(columnKinds))
|
||||
|
|
@ -147,7 +153,7 @@ func init() {
|
|||
listCmd.Flags().BoolVar(&noKeys, "no-keys", false, "suppress the key column")
|
||||
listCmd.Flags().BoolVar(&noValues, "no-values", false, "suppress the value column")
|
||||
listCmd.Flags().BoolVarP(&ttl, "ttl", "t", false, "append a TTL column when entries expire")
|
||||
listCmd.Flags().BoolVar(&noHeader, "no-header", false, "omit the header rows")
|
||||
listCmd.Flags().VarP(&format, "format", "o", "render output format (table|csv|markdown|html)")
|
||||
listCmd.Flags().BoolVar(&header, "header", false, "include header row")
|
||||
listCmd.Flags().VarP(&format, "format", "o", "output format (table|tsv|csv|markdown|html)")
|
||||
rootCmd.AddCommand(listCmd)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ func (e *formatEnum) String() string {
|
|||
|
||||
func (e *formatEnum) Set(v string) error {
|
||||
switch v {
|
||||
case "table", "csv", "html", "markdown":
|
||||
case "table", "tsv", "csv", "html", "markdown":
|
||||
*e = formatEnum(v)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("must be one of \"table\", \"csv\", \"html\", or \"markdown\"")
|
||||
return fmt.Errorf("must be one of \"table\", \"tsv\", \"csv\", \"html\", or \"markdown\"")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -44,20 +44,22 @@ var (
|
|||
noKeys bool = false
|
||||
noValues bool = false
|
||||
ttl bool = false
|
||||
noHeader bool = false
|
||||
header bool = false
|
||||
format formatEnum = "table"
|
||||
)
|
||||
|
||||
func enrichFlags() (ListArgs, error) {
|
||||
var renderFunc func(tw table.Writer)
|
||||
switch format.String() {
|
||||
case "tsv":
|
||||
renderFunc = func(tw table.Writer) { tw.RenderTSV() }
|
||||
case "csv":
|
||||
renderFunc = func(tw table.Writer) { tw.RenderCSV() }
|
||||
case "html":
|
||||
renderFunc = func(tw table.Writer) { tw.RenderHTML() }
|
||||
case "markdown":
|
||||
renderFunc = func(tw table.Writer) { tw.RenderMarkdown() }
|
||||
default:
|
||||
case "table":
|
||||
renderFunc = func(tw table.Writer) { tw.Render() }
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +68,7 @@ func enrichFlags() (ListArgs, error) {
|
|||
}
|
||||
|
||||
return ListArgs{
|
||||
header: !noHeader,
|
||||
header: header,
|
||||
key: !noKeys,
|
||||
value: !noValues,
|
||||
ttl: ttl,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue