Skip to content

[Help] Fix argument group ordering.#1015

Merged
tjprescott merged 2 commits into
Azure:masterfrom
tjprescott:FixHelpGrouping
Sep 29, 2016
Merged

[Help] Fix argument group ordering.#1015
tjprescott merged 2 commits into
Azure:masterfrom
tjprescott:FixHelpGrouping

Conversation

@tjprescott

Copy link
Copy Markdown
Member

Fixes #976. Previously any group not within the static "priorities" dictionary in the _help.py file was assigned a priority of 1, meaning many groups shared the same priority. When the parameters were then sorted alphabetically, it could result in multiple group labels being printed. This solution ensures argument groups not in the static dictionary (a) don't need to be added and (b) don't have overlapping priorities.

priority = 2
# get alphabetical list of groups and ensure they are in the group priority dictionary
group_list = sorted(list(set(group_list)))
for group in [g for g in group_list if g not in self.priorities]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code logic appears correct. One suggestion though, it usually concerns me for a loop around a collection also updates the collection itself.
If i get it right, the loop can be simplified as following. The group_list won't contains duplicate as you have used "set"

  for group_name in group_list:
      self.priorities[group] = priority
      priority += 1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The problem here is that some of the groups are already in the static dictionary ('Resource Id', 'Global', etc.), so the recommended change would actually change those, which is not what I want. I only want to add entries not already in the static dictionary (and I don't want people to have to add their groups to the static dictionary).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for pointing this out. Per our discussion, let us do filter at a line above when we sort the group


def get_group_priority(self, group_name):
key = self.priorities.get(group_name, 0)
return "%06d" % key

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just a question, why we need to expand to 6 digits, is the comparison based on string, not int?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That was the logic Burt originally had, so I didn't want to deviate from without him here to review the change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sounds good.


def get_group_priority(self, group_name):
key = self.priorities.get(group_name, 0)
return "%06d" % key

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sounds good.

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.

5 participants