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

Sort plugin names in a natural order #1166

Merged
merged 1 commit into from
Jul 5, 2018

Conversation

adshmh
Copy link
Contributor

@adshmh adshmh commented Jun 30, 2018

- What I did
Sorted the output of plugin list command by plugin name. fixes #1164

- How I did it
Added sort functionality to cli/command/plugin/list.go and unit tests to cli/command/plugin/list_test.go

- How to verify it

  1. Create multiple plugins
  2. Run docker plugin ls
  3. Output is sorted based on plugins' names

- Description for the changelog
docker plugin ls output is sorted based on plugin name

- A picture of a cute animal (not mandatory but encouraged)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one nit, but LGTM otherwise

@@ -2,11 +2,15 @@ package plugin

import (
"context"
"sort"

"vbom.ml/util/sortorder"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you group this import with the other imports below?

@thaJeztah
Copy link
Member

ping @cpuguy83

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -17,6 +21,12 @@ type listOptions struct {
filter opts.FilterOpt
}

type byName []*types.Plugin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use sort.Slice instead of defining a type for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. I will update the PR to use sort.Slice


func (n byName) Len() int { return len(n) }
func (n byName) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
func (n byName) Less(i, j int) bool { return sortorder.NaturalLess(n[i].Name, n[j].Name) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need this lib. Should be able to compare strings directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this library compares integers embedded in strings by value. In the test case here, i.e. order of names: plugin-10-foo and plugin-2-foo, the result of direct string compare in go is opposite of that provided by this library.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; it was added for natural sort

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
@adshmh adshmh force-pushed the add-sort-to-plugin-list branch from 89f441c to 26151d9 Compare July 5, 2018 16:37
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still LGTM

as a follow up, we can probably update the other parts of the code to use sort.Slice() as well

@cpuguy83 good to go?

Copy link
Collaborator

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cpuguy83 cpuguy83 merged commit 8160759 into docker:master Jul 5, 2018
@GordonTheTurtle GordonTheTurtle added this to the 18.07.0 milestone Jul 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docker plugin ls command output is not sorted by plugin name
6 participants