-
Notifications
You must be signed in to change notification settings - Fork 38
/
ui_flags.go
52 lines (43 loc) · 1.24 KB
/
ui_flags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"github.com/cppforlife/go-cli-ui/ui"
uitable "github.com/cppforlife/go-cli-ui/ui/table"
cmdcore "github.com/k14s/kbld/pkg/kbld/cmd/core"
"github.com/spf13/cobra"
)
type UIFlags struct {
TTY bool
Color bool
JSON bool
NonInteractive bool
Columns []string
}
func (f *UIFlags) Set(cmd *cobra.Command, flagsFactory cmdcore.FlagsFactory) {
cmd.PersistentFlags().BoolVar(&f.TTY, "tty", false, "Force TTY-like output")
cmd.PersistentFlags().BoolVar(&f.Color, "color", true, "Set color output")
cmd.PersistentFlags().BoolVar(&f.JSON, "json", false, "Output as JSON")
cmd.PersistentFlags().BoolVarP(&f.NonInteractive, "yes", "y", false, "Assume yes for any prompt")
cmd.PersistentFlags().StringSliceVar(&f.Columns, "column", nil, "Filter to show only given columns")
}
func (f *UIFlags) ConfigureUI(ui *ui.ConfUI) {
ui.EnableTTY(f.TTY)
if f.Color {
ui.EnableColor()
}
if f.JSON {
ui.EnableJSON()
}
if f.NonInteractive {
ui.EnableNonInteractive()
}
if len(f.Columns) > 0 {
headers := []uitable.Header{}
for _, col := range f.Columns {
headers = append(headers, uitable.Header{
Key: uitable.KeyifyHeader(col),
Hidden: false,
})
}
ui.ShowColumns(headers)
}
}