-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add Categories and Checks CLI commands #339
Conversation
7fbb19b
to
33d5e39
Compare
// Create the runner if not already initialized. | ||
if ( is_null( $runner ) ) { | ||
$runner = new CLI_Checks_Runner(); | ||
} | ||
|
||
// Make sure we are using the correct runner instance. | ||
if ( ! ( $runner instanceof CLI_Checks_Runner ) ) { | ||
WP_CLI::error( | ||
__( 'CLI Checks Runner was not initialized correctly.', 'plugin-check' ) | ||
); | ||
} |
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.
Hmm I really don't like that this simple command requires a new *_Runner
just because the check registration happens in Abstract_Check_Runner::register_checks()
Especially since the current CLI_Runner
class is mostly a hack anyway
I think we need some refactoring to move the registration out of the runner class, maybe to a factory method on Default_Check_Repository
or so.
Listing all registered checks should be as simple as getting a Default_Check_Repository
and listing what's in there.
cc @felixarntz for thoughts
/* | ||
* Bail early if the Plugin Checker is not activated. | ||
* | ||
* If the Plugin Checker is not activated, it will throw an error and | ||
* CLI commands won't be usable. | ||
*/ | ||
if ( is_plugin_inactive( $this->plugin_context->basename() ) ) { | ||
WP_CLI::error( | ||
__( 'Plugin Checker is not active.', 'plugin-check' ) | ||
); | ||
} |
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 code can be removed as it's dead code.
This class can only ever be loaded when the plugin is active, so it does not make sense to check whether the plugin is active.
/** | ||
* Plugin check categories command. | ||
*/ | ||
final class Plugin_Check_Categories_Command { |
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.
Would it be possible to add some functional tests for this command in tests/behat/features/list-categories.feature
?
/** | ||
* Plugin check checks command. | ||
*/ | ||
final class Plugin_Check_Checks_Command { |
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.
Would it be possible to add some functional tests for this command in tests/behat/features/list-checks.feature
?
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 PR @ernilambar! Looks great so far. I've added a few points of feedback below. Let me know if you have any questions.
361e9f3
to
0074b28
Compare
Code is updated as per the comments. New commands will be:
Behat tests implementation for new commands is remaining. @swissspidy Is it possible to run behat tests in local environment? Or is it implemented now in GitHub actions only? |
Use You may need to run |
e6d16e9
to
29e177f
Compare
PR ready for review.
|
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.
@ernilambar The logic itself looks great now. I think there are a couple places where we can drastically simplify the code and avoid duplicate code, most importantly by using the existing Plugin_Check_Command
class for the 2 new CLI commands.
aa2f059
to
e6ea8b2
Compare
PR has been update as per the review comments. Note:
|
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.
@ernilambar I think this is almost good to go now. A few follow up feedback points.
c07f66f
to
772805c
Compare
772805c
to
e965985
Compare
e965985
to
1934de3
Compare
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 looks great @ernilambar!
Just a few last nit-picks, but no real blockers. Thank you for all your work on this! 🙌
In the follow-up PR, it's essential to update the documentation to reflect the changes made by this pull request. Specifically, we removed the The affected documentation files that need updating are: |
c6680b1
to
b1eb98b
Compare
b1eb98b
to
4b879dc
Compare
PR updated as per the comments. Fixed spacing issues and improved function docs. |
Fixes #303
Command:
wp plugin list-check-categories
Output:
Command:
wp plugin list-checks
Output: