Adding parameters to your CLI command
Our CLI application is very useful to get a quick view of the upcoming deadlines within a week, but what about the upcoming deadlines for the month? We could just change the time parameter in our SQL query, but that would not be very practical, so let’s add arguments to our CLI command to allow for better flexibility.
We’ll add an option to our command to pass the number of days we want to consider for the deadline.
As we saw in the previous section, Introducing generic options for Joomla! CLI, we added two dashes before the name of the option. We are calling our option days
, so our command will look like this:
php joomla.cli spm:task:deadline --days 7
Here, we can replace 7
with any number of days when executing our command.
Joomla! provides several interesting methods to make it easier to define these CLI options. Let’s start editing the src/plugins/console/spm/src/CliCommand/SpmTaskDeadlineCommand.php
file...