-
Notifications
You must be signed in to change notification settings - Fork 77
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
Introduce list
command in CLI
#914
Conversation
test "`help perform` invites the user to use `maintenance_tasks list` with proper rewrapping" do | ||
expected_output = <<~OUTPUT.indent(2) | ||
`maintenance_tasks perform` will run the Maintenance Task specified by the [TASK NAME] argument. | ||
|
||
Use `maintenance_tasks list` to get a list of all available tasks. | ||
OUTPUT | ||
|
||
assert_output(Regexp.union(expected_output)) do | ||
CLI.start(["help", "perform"]) | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is probably unnecessary. (It tests Thor's standard behaviour, not anything related to maintenance_tasks' code.)
Remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment about the help perform
test or the list
one? I'd prefer to keep the list
one, but fine with dropping the help perform
one since we're matching on a simple string.
There was a problem hiding this comment.
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!
GitHub has made commenting on code blocks almost invisible... 😞
Yes, I was commenting on the help perform
test, which does not test anything but how Thor is supposed to work (long_desc
+ rewrapping).
Will remove!
@@ -3,6 +3,9 @@ | |||
# Configure Rails Environment | |||
ENV["RAILS_ENV"] = "test" | |||
|
|||
# Don't wrap output in tests | |||
ENV["THOR_COLUMNS"] = "200" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more resilient than the old Thor::Base.shell.any_instance.stubs(:terminal_width).returns(200)
, since THOR_COLUMNS
has been around for more than 10 years, and it still works with Thor 1.3.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally support the idea of not listing all available tasks in the help message for perform
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
test "`help perform` invites the user to use `maintenance_tasks list` with proper rewrapping" do | ||
expected_output = <<~OUTPUT.indent(2) | ||
`maintenance_tasks perform` will run the Maintenance Task specified by the [TASK NAME] argument. | ||
|
||
Use `maintenance_tasks list` to get a list of all available tasks. | ||
OUTPUT | ||
|
||
assert_output(Regexp.union(expected_output)) do | ||
CLI.start(["help", "perform"]) | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment about the help perform
test or the list
one? I'd prefer to keep the list
one, but fine with dropping the help perform
one since we're matching on a simple string.
3e0171f
to
7ed7afd
Compare
This is an alternative to #913, which I actually prefer.
A couple months ago, in #877, I did some weird stuff in order to defer task loading when it's actually necessary. The issue was that we needed the list of all tasks to set the long description of the
perform
command.I realized that it might actually allow us to keep code more standard and simple, if instead of that, we provided a
list
command that loads and lists all available tasks.Pros
define_singleton_method :long_description
, which relies on not-so-public APIs, and as shown by the release of Thor 1.3.0, is brittle.help perform
does not flood the terminal anymore. If I ranmaintenance_tasks help perform
, chances are I wanted to see what it does, parameters it takes and its syntax. These things were pushed off screen when there are a lot of tasks available.list
command is purely made to output a list of tasks, no indentation, no empty lines in between. It's more favorable to exporting the list to a text file or grepping for something.Cons
maintenance_tasks help perform
will not return the task list anymore. Anyone relying on that will have to update what they do.I like this approach better than the one I had first which was trying to work around the issue in complicated ways.
Merging this will close #913 as it'll be unnecessary.