Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add column ordering support to cliui table #16055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mafredri opened this issue Jan 7, 2025 · 2 comments · Fixed by #16843
Closed

Add column ordering support to cliui table #16055

mafredri opened this issue Jan 7, 2025 · 2 comments · Fixed by #16843
Assignees

Comments

@mafredri
Copy link
Member

mafredri commented Jan 7, 2025

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.

@mtojek
Copy link
Member

mtojek commented Mar 6, 2025

@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?

@mafredri
Copy link
Member Author

mafredri commented Mar 6, 2025

@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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants