Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/base/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ func AddGlobalFlags(cmd *cobra.Command) {
cmd.PersistentFlags().Int("http-timeout", 30, "HTTP timeout ( seconds )")
cmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output")
cmd.PersistentFlags().StringP("output", "o", "text", "output format (text/json/yaml)")
// define help flag without shorthand before cobra adds it by default to avoid conflict with no-header flag shorthand
cmd.PersistentFlags().Bool("help", false, "Print usage")
cmd.PersistentFlags().Lookup("help").Hidden = true
cmd.PersistentFlags().BoolP("no-header", "h", false, "print output without headers")
}

func AddFormatFlags(cmd *cobra.Command) {
Expand Down
3 changes: 3 additions & 0 deletions internal/output/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Formatter struct {
pageView bool
fieldsToShow []string
fieldList bool
header bool
}

// NewFormatter creates new formatter with specified io.Writer
Expand All @@ -28,6 +29,7 @@ func NewFormatter(cmd *cobra.Command, manager *config.Manager) *Formatter {
template, _ := manager.GetResolvedStringValue(cmd, "template")
fields, _ := manager.GetResolvedStringSliceValue(cmd, "field")
fieldList, _ := manager.GetResolvedBoolValue(cmd, "field-list")
noHeader, _ := manager.GetResolvedBoolValue(cmd, "no-header")

return &Formatter{
writer: cmd.OutOrStdout(),
Expand All @@ -36,6 +38,7 @@ func NewFormatter(cmd *cobra.Command, manager *config.Manager) *Formatter {
pageView: pageView,
fieldsToShow: fields,
fieldList: fieldList,
header: !noHeader,
}
}

Expand Down
10 changes: 6 additions & 4 deletions internal/output/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ func (f *Formatter) formatText(v any) error {

orderedFields := f.getOrderedFields(entity)

headers := make([]string, 0, len(orderedFields))
for _, field := range orderedFields {
headers = append(headers, field.GetName())
if f.header {
headers := make([]string, 0, len(orderedFields))
for _, field := range orderedFields {
headers = append(headers, field.GetName())
}
fmt.Fprintln(w, strings.Join(headers, "\t"))
}
fmt.Fprintln(w, strings.Join(headers, "\t"))

value := reflect.ValueOf(v)
return processValue(value, func(item any) error {
Expand Down
Loading