Skip to content
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

cmd/member: sort the result before printing #39

Open
tormath1 opened this issue Oct 2, 2020 · 3 comments
Open

cmd/member: sort the result before printing #39

tormath1 opened this issue Oct 2, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@tormath1
Copy link
Contributor

tormath1 commented Oct 2, 2020

The API call returns a member list in a different order between runs. We should sort it before printing the result in order to ease diff between two runs.

NB: Can be extrapolated to other list commands.

[doc]

@tormath1 tormath1 added enhancement New feature or request good first issue Good for newcomers labels Oct 2, 2020
@Amirhossein2000
Copy link

Hi,
Which file need edit?

@tormath1
Copy link
Contributor Author

tormath1 commented Oct 12, 2020

Hi @Amirhossein2000, thanks for your interest !

To provide more information, the CLI returns the API result using the printer package (printer). The sort must be done for the printer.Table.

To abstract the things, the printer expects a pointer to a struct or an array of pointers, this is how swagger returns the things. For the table, we first extract the headers (exported struct fields name) and from this headers we extract the associated values.

headers, entries, err := generate(obj, opts)

An output example would be:

headers -> ["ID", "NAME"]
values -> [[1, 3, 2], ["foo", "bar", "foobar"]

and so the result will be printed like

| ID | MEMBER |
|----|--------|
| 1  | foo    |
| 3  | bar    |
| 2  | foobar |

The issue is that the values are not in the same order between each run, so it's not easy to run deterministic tasks (like diff / sorting) between two outputs.

The easiest solution I have currently in mind, would be to pass (CLI flag with default value for each services ?) to the printer.Options the column on which one we want to sort the output and it would make sense for the next iterations on the printer.Table since we would like to be able to select the columns to display.

// print the result on the standard output
if err := p.Print(mbs, printer.Options{}, os.Stdout); err != nil {
return errors.Wrap(err, "unable to print result")
}

If you still have an interest in the thing, you can easily test your work using the printer.Table test file. Thanks again and let us know it goes !

@fhacloid
Copy link
Contributor

Issue still existing.

@fhacloid fhacloid self-assigned this Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants