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

Allow to Override Order of Commands in Help #642

Merged

Conversation

alessio-signorini
Copy link
Contributor

The current implementation of the help function sorts the command lexicographically. A request for enhancement (#361) has been open for a while and it seems that people are resorting to hacks to change it.

This PR adds a class method called sort_commands!. The default implementation maintains the lexicographic ordering but the method can be easily overridden by the subclass to obtain any sort of ordering.

Here is a quick example that would place the help command first

class MyScript < Thor
  ...
  def self.sort_commands!(list)
    list.sort_by! do |a,b|
      a[0] == :help ? -1 : a[0] <=> b[0]
    end
  end
end

@Roriz
Copy link

Roriz commented Jan 2, 2020

up

.travis.yml Outdated Show resolved Hide resolved
spec/sort_spec.rb Outdated Show resolved Hide resolved
spec/sort_spec.rb Outdated Show resolved Hide resolved
@alessio-signorini
Copy link
Contributor Author

@rafaelfranca, @Roriz - is it time to merge this? 😃

@alexevanczuk
Copy link

Hi everyone! Are you still hoping to merge this PR? It would be a great help!

@rafaelfranca rafaelfranca force-pushed the allow-to-override-commands-sorting branch from 3447a54 to a562cdc Compare May 11, 2023 20:46
Thor will not inherit from any other class, and the goal is to allow
subclasses to override the sort_commands! method, so we don't need to
check for super.
@rafaelfranca rafaelfranca force-pushed the allow-to-override-commands-sorting branch from a562cdc to b2590c1 Compare May 11, 2023 20:47
@rafaelfranca rafaelfranca merged commit 91aa66f into rails:main May 11, 2023
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.

4 participants