Skip to content

Add column ordering support to cliui table #16055

Description

@mafredri

Currently CLI table columns are ordered in the order they were defined in the structure. This means that either a new data type has to be created and data copied over meticulously and kept in sync with future changes, or the columns will appear in an unsatisfactory order. The order can be especially problematic when embedding other structures.

There are two benefits to allowing the order to be defined:

  1. No more duplicate data structures and copying over (risk of changes/new data fields not being propagated)
  2. Users can define the column order themselves (it could follow the given --colum flag)

This also came up in #15940 (comment) and is something I'd like to utilize in #16030.

Activity

  1. self-assigned this
    on Mar 6, 2025
  2. mtojek commented on Mar 6, 2025

    @mtojek
    Member

    @mafredri A custom parameter like --column="queue,created_at,status" should be a low-hanging fruit to add, but I wanted to ask about your guidance for sorting. Should we preserve the default sorting or take the first column instead? Right now, it defaults to CreatedAt. Thoughts?

  3. mafredri commented on Mar 6, 2025

    @mafredri
    MemberAuthor

    @mtojek We don't need to touch row sorting here. My intention with this issue is to focus on programmatic column ordering instead of the current struct field order (we already have a --column flag, btw). So it's enough if we can define our preferred order in cli/mycmd.go.

    Maybe we just follow the order specified in cliui.TableFormat(T{}, []string{"first", "second"})?

    (Table row sorting can be handled by a separate --order or --sort flag, IMO.)

    If we later on support column ordering as given by the user, that's OK too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions