Description
The plugin should extend the current wp plugin command, which will do single or multiple checks. The CLI command class file should be placed in the CLI directory under the includes directory. The class name should be WordPress\Plugin_Check\CLI\Plugin_Check_Command.
This issue is dependent on:
Sub-Command
check
Command arguments
<plugin>
The plugin to check. Plugin name.
--checks=<checks>
Only runs checks provided as an argument in comma-separated values, e.g. enqueued-scripts, escaping. Otherwise runs all checks.
--flag=<flags>
Limit the checks being executed according to their flags, e.g. stable, beta or experimental. Default is stable.
--format=<format>
Format to display the results. Options are table, csv, and json. The default will be a table.
--fields=<fields>
Limit displayed results to a subset of fields provided.
--ignore-warnings
Limit displayed results to exclude warnings.
--ignore-errors
Limit displayed results to exclude errors.
Examples
wp plugin check akismet
wp plugin check akismet --check=escaping
wp plugin check akismet --format=json
Acceptance Criteria
Plugin_Check_Command command class should be created and exists at includes/CLI
- Constructor should receive
Plugin_Context $plugin_context
- Command should be registered using
WP_CLI::add_command( 'plugin check', __CLASS_NAMESPACE__ . '\register_command' ); in the Plugin_Main file.
- Provided
--checks argument, command should process only these checks
- Provided
--flag argument, command should process only flagged checks, default should be stable
- Provided
--format argument, command should display results in that format
- Provided
--fields argument, command should display results with these fields only
- Provided
--ignore-warnings argument, command should display results with errors only
- Provided
--ignore-errors argument, command should display results with warnings only
- The
Plugin_Check_Command has a public check( array $args, array $assoc_args ) method.
- The method will attempt to resolve the plugin name passed in the
$args array. If the plugin does not exist and a WP_CLI::error() is printed.
- The
CLI_Runner classes run() method is called. The CLI_Runner is instantiated and prepared earlier in the process so no parameters are needed to be passed.
- The
run() method is called in a try/catch block. If an exception is thrown by the method it is caught and printed as a WP_CLI:error().
- The
run() method will return an instance of the Check_Result class.
- If the
--ignore-warnings option is exists in the $assoc_args, the warnings are ignored in the Check_Result instance.
- If the
--ignore-errors option is exists in the $assoc_args, the errors are ignored in the Check_Result instance.
- The
Check_Result are then printed by the command looping over each of the files, displaying errors first and warnings second.
- A new
WP_CLI\Formatter class is created based on the --format option passed in the $assoc_args array. It will also use the --fields option to set what fields are displayed.
- Each file printed will display both errors and warnings by combining the
$errors and $warnings together and sorting each result by the file line number.
- Results are then printed using the
WP_CLI::line() and WP_CLI\Formatter class created earlier. Results are displayed with the filename first and each subsequent line an individual error or warning.
- Additional protected methods can be created to encapsulate logic within the run method.
- A protected
get_plugin_from_args( array $args ) method can be used to find the plugin requested from the CLI arguments as well as check the plugin exist.
- A protected
get_formatter( array $assoc_args ) method can be used to create the WP_CLI\Formatter based on the CLI arguments passed.
- A protected
flatten_file_results( array $file_errors, array $file_warnings ) method can be created to handle combining a files errors and warning into a single array and order them by file number.
- A protected
display_results( WP_CLI\Formatter $formatter, string $file_name, array $file_results ) method can be used to display the results using the file name, flattened results array and the WP_CLI\Formatter created earlier.
Tests Coverage
- Executing CLI command with default arguments should run expected checks
- Execute CLI command with different arguments set for
--checks, --flag, --format, --fields, --ignore-warnings, --ignore-errors should run expected checks and return expected results
- Execute CLI command without required arguments should give error
Description
The plugin should extend the current
wp plugincommand, which will do single or multiple checks. The CLI command class file should be placed in the CLI directory under the includes directory. The class name should beWordPress\Plugin_Check\CLI\Plugin_Check_Command.This issue is dependent on:
Sub-Command
checkCommand arguments
<plugin>The plugin to check. Plugin name.
--checks=<checks>Only runs checks provided as an argument in comma-separated values, e.g. enqueued-scripts, escaping. Otherwise runs all checks.
--flag=<flags>Limit the checks being executed according to their flags, e.g. stable, beta or experimental. Default is stable.
--format=<format>Format to display the results. Options are table, csv, and json. The default will be a table.
--fields=<fields>Limit displayed results to a subset of fields provided.
--ignore-warningsLimit displayed results to exclude warnings.
--ignore-errorsLimit displayed results to exclude errors.
Examples
wp plugin check akismetwp plugin check akismet --check=escapingwp plugin check akismet --format=jsonAcceptance Criteria
Plugin_Check_Commandcommand class should be created and exists atincludes/CLIPlugin_Context $plugin_contextWP_CLI::add_command( 'plugin check', __CLASS_NAMESPACE__ . '\register_command' );in thePlugin_Mainfile.--checksargument, command should process only these checks--flagargument, command should process only flagged checks, default should bestable--formatargument, command should display results in that format--fieldsargument, command should display results with these fields only--ignore-warningsargument, command should display results with errors only--ignore-errorsargument, command should display results with warnings onlyPlugin_Check_Commandhas a publiccheck( array $args, array $assoc_args )method.$argsarray. If the plugin does not exist and aWP_CLI::error()is printed.CLI_Runnerclassesrun()method is called. TheCLI_Runneris instantiated and prepared earlier in the process so no parameters are needed to be passed.run()method is called in a try/catch block. If an exception is thrown by the method it is caught and printed as aWP_CLI:error().run()method will return an instance of theCheck_Resultclass.--ignore-warningsoption is exists in the$assoc_args, the warnings are ignored in theCheck_Resultinstance.--ignore-errorsoption is exists in the$assoc_args, the errors are ignored in theCheck_Resultinstance.Check_Resultare then printed by the command looping over each of the files, displaying errors first and warnings second.WP_CLI\Formatterclass is created based on the--formatoption passed in the$assoc_argsarray. It will also use the--fieldsoption to set what fields are displayed.$errorsand$warningstogether and sorting each result by the file line number.WP_CLI::line()andWP_CLI\Formatterclass created earlier. Results are displayed with the filename first and each subsequent line an individual error or warning.get_plugin_from_args( array $args )method can be used to find the plugin requested from the CLI arguments as well as check the plugin exist.get_formatter( array $assoc_args )method can be used to create theWP_CLI\Formatterbased on the CLI arguments passed.flatten_file_results( array $file_errors, array $file_warnings )method can be created to handle combining a files errors and warning into a single array and order them by file number.display_results( WP_CLI\Formatter $formatter, string $file_name, array $file_results )method can be used to display the results using the file name, flattened results array and theWP_CLI\Formattercreated earlier.Tests Coverage
--checks,--flag,--format,--fields,--ignore-warnings,--ignore-errorsshould run expected checks and return expected results