X Tutup
Skip to content

Commit 625505d

Browse files
committed
Fix assigning null Exporter
1 parent 7ec5b0f commit 625505d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pkg/cmdutil/json_flags.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ func AddJSONFlags(cmd *cobra.Command, exportTarget *Exporter, fields []string) {
3333
}
3434
}
3535
if export, err := checkJSONFlags(c); err == nil {
36-
*exportTarget = export
36+
if export == nil {
37+
*exportTarget = nil
38+
} else {
39+
*exportTarget = export
40+
}
3741
} else {
3842
return err
3943
}
@@ -49,7 +53,7 @@ func AddJSONFlags(cmd *cobra.Command, exportTarget *Exporter, fields []string) {
4953
})
5054
}
5155

52-
func checkJSONFlags(cmd *cobra.Command) (*ExportFormat, error) {
56+
func checkJSONFlags(cmd *cobra.Command) (*exportFormat, error) {
5357
f := cmd.Flags()
5458
jsonFlag := f.Lookup("json")
5559
jqFlag := f.Lookup("jq")
@@ -61,7 +65,7 @@ func checkJSONFlags(cmd *cobra.Command) (*ExportFormat, error) {
6165
return nil, errors.New("cannot use `--web` with `--json`")
6266
}
6367
jv := jsonFlag.Value.(pflag.SliceValue)
64-
return &ExportFormat{
68+
return &exportFormat{
6569
fields: jv.GetSlice(),
6670
filter: jqFlag.Value.String(),
6771
template: tplFlag.Value.String(),
@@ -79,17 +83,17 @@ type Exporter interface {
7983
Write(w io.Writer, data interface{}, colorEnabled bool) error
8084
}
8185

82-
type ExportFormat struct {
86+
type exportFormat struct {
8387
fields []string
8488
filter string
8589
template string
8690
}
8791

88-
func (e *ExportFormat) Fields() []string {
92+
func (e *exportFormat) Fields() []string {
8993
return e.fields
9094
}
9195

92-
func (e *ExportFormat) Write(w io.Writer, data interface{}, colorEnabled bool) error {
96+
func (e *exportFormat) Write(w io.Writer, data interface{}, colorEnabled bool) error {
9397
buf := bytes.Buffer{}
9498
encoder := json.NewEncoder(&buf)
9599
encoder.SetEscapeHTML(false)

0 commit comments

Comments
 (0)
X Tutup