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()
|
output := cmd.OutOrStdout()
|
||||||
tw := table.NewWriter()
|
tw := table.NewWriter()
|
||||||
tw.SetOutputMirror(output)
|
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
|
var maxContentWidths []int
|
||||||
maxContentWidths = make([]int, len(columnKinds))
|
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(&noKeys, "no-keys", false, "suppress the key column")
|
||||||
listCmd.Flags().BoolVar(&noValues, "no-values", false, "suppress the value 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().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().BoolVar(&header, "header", false, "include header row")
|
||||||
listCmd.Flags().VarP(&format, "format", "o", "render output format (table|csv|markdown|html)")
|
listCmd.Flags().VarP(&format, "format", "o", "output format (table|tsv|csv|markdown|html)")
|
||||||
rootCmd.AddCommand(listCmd)
|
rootCmd.AddCommand(listCmd)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,11 @@ func (e *formatEnum) String() string {
|
||||||
|
|
||||||
func (e *formatEnum) Set(v string) error {
|
func (e *formatEnum) Set(v string) error {
|
||||||
switch v {
|
switch v {
|
||||||
case "table", "csv", "html", "markdown":
|
case "table", "tsv", "csv", "html", "markdown":
|
||||||
*e = formatEnum(v)
|
*e = formatEnum(v)
|
||||||
return nil
|
return nil
|
||||||
default:
|
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
|
noKeys bool = false
|
||||||
noValues bool = false
|
noValues bool = false
|
||||||
ttl bool = false
|
ttl bool = false
|
||||||
noHeader bool = false
|
header bool = false
|
||||||
format formatEnum = "table"
|
format formatEnum = "table"
|
||||||
)
|
)
|
||||||
|
|
||||||
func enrichFlags() (ListArgs, error) {
|
func enrichFlags() (ListArgs, error) {
|
||||||
var renderFunc func(tw table.Writer)
|
var renderFunc func(tw table.Writer)
|
||||||
switch format.String() {
|
switch format.String() {
|
||||||
|
case "tsv":
|
||||||
|
renderFunc = func(tw table.Writer) { tw.RenderTSV() }
|
||||||
case "csv":
|
case "csv":
|
||||||
renderFunc = func(tw table.Writer) { tw.RenderCSV() }
|
renderFunc = func(tw table.Writer) { tw.RenderCSV() }
|
||||||
case "html":
|
case "html":
|
||||||
renderFunc = func(tw table.Writer) { tw.RenderHTML() }
|
renderFunc = func(tw table.Writer) { tw.RenderHTML() }
|
||||||
case "markdown":
|
case "markdown":
|
||||||
renderFunc = func(tw table.Writer) { tw.RenderMarkdown() }
|
renderFunc = func(tw table.Writer) { tw.RenderMarkdown() }
|
||||||
default:
|
case "table":
|
||||||
renderFunc = func(tw table.Writer) { tw.Render() }
|
renderFunc = func(tw table.Writer) { tw.Render() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,7 +68,7 @@ func enrichFlags() (ListArgs, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ListArgs{
|
return ListArgs{
|
||||||
header: !noHeader,
|
header: header,
|
||||||
key: !noKeys,
|
key: !noKeys,
|
||||||
value: !noValues,
|
value: !noValues,
|
||||||
ttl: ttl,
|
ttl: ttl,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue