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

Introduce list command in CLI #914

Merged
merged 4 commits into from
Nov 1, 2023
Merged

Introduce list command in CLI #914

merged 4 commits into from
Nov 1, 2023

Conversation

davidstosik
Copy link
Contributor

@davidstosik davidstosik commented Oct 31, 2023

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

  • The CLI still doesn't need to load all tasks at "boot". (the original goal of Avoid loading all tasks when first loading the CLI #877)
  • We don't need to use meta-programming to 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.
  • The output of help perform does not flood the terminal anymore. If I ran maintenance_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.
  • The 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.
  • It works the same for the new Thor 1.3.0 and older versions. No weird version switching.

Cons

  • I can only think of one: CLI behaviour changes: 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.

Comment on lines 88 to 99
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

Copy link
Contributor Author

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?

Copy link
Contributor

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.

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!

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"
Copy link
Contributor Author

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.

@davidstosik davidstosik requested a review from a team October 31, 2023 04:54
Copy link
Contributor

@nvasilevski nvasilevski left a 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!

Copy link
Contributor

@adrianna-chang-shopify adrianna-chang-shopify left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

Comment on lines 88 to 99
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

Copy link
Contributor

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.

@davidstosik davidstosik merged commit 39ed7c8 into main Nov 1, 2023
33 checks passed
@davidstosik davidstosik deleted the sto/cli-list branch November 1, 2023 07:37
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.

3 participants