-
Notifications
You must be signed in to change notification settings - Fork 106
/
ui_flags.go
52 lines (43 loc) · 1.21 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
// Copyright 2020 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"github.com/cppforlife/go-cli-ui/ui"
uitable "github.com/cppforlife/go-cli-ui/ui/table"
"github.com/spf13/cobra"
cmdcore "github.com/vmware-tanzu/carvel-kapp/pkg/kapp/cmd/core"
)
type UIFlags struct {
TTY bool
Color bool
JSON bool
NonInteractive bool
Columns []string
}
func (f *UIFlags) Set(cmd *cobra.Command, _ cmdcore.FlagsFactory) {
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) {
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)
}
}