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

added SortCommands to enable sorting of sub commands #144

Closed
wants to merge 1 commit into from

Conversation

mlitvin
Copy link
Contributor

@mlitvin mlitvin commented Sep 19, 2016

Allow sorting the commands so that the usage will give the output in alphabetical order

  1. Why do I need it? I have a modular application where sub commands are registered by the init function of various files, so for example on different OSes the list of commands may be different.

The result is that the order of command registration is not controlled and the usage message returns with a "strange" ordering.

  1. Why not implement it in the usage template level?
    Because this will require implementing this for each usage template (to give one with alphabetical ordering and one without). I found little effect on sorting other than usage (mainly the choosing of the default sub command if more than one is specified), and I opted for simplicity.

@alecthomas
Copy link
Owner

I can understand the use case, but not quite why this couldn't just be in your own custom template in your app?

@mlitvin
Copy link
Contributor Author

mlitvin commented Sep 20, 2016

There are two general issues with doing it within a custom template:

Implementation: I'll need access in the the template to a sorted list of commands or a sorting function. So it will require code changes to support this kind of custom template. For example adding
func (c *CmdGroupModel)SortedCommands() []*CmdModel would do the trick.

Maintenance: I'll need to copy the proper usage template to my own code, replace .Commands with .SortedCommands in the appropriate place. Then whenever bugs are fixed in the the original template I would have to manually identify and merge them to my own code (it won't suffice to just go get the latest and greatest)

@alecthomas
Copy link
Owner

Okay, in that case I think your requirements are covered by #90 ("Usage templates should allow custom template functions/context."). The idea is that customisable help rendering will be supported by providing the ApplicationModel, context.FuncMap, etc., then be able to do whatever you prefer.

Part of this is already present in that app.Model() returns the model used in the templates, but the rest of the context isn't available yet unfortunately.

For now, I'm afraid, I'd rather not merge custom features like this. Sorry.

@alecthomas alecthomas closed this Sep 20, 2016
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 this pull request may close these issues.

2 participants