Koldy framework offers easy way of writing scripts for Command Line Interface (CLI).

To make your own script for CLI env, create php file in application/scripts or under application/modules/[module]/scripts. The file name is allowed to have only English lower and upper case letters, numbers, dashes (-) and underscores (_). All other characters are not valid and framework will throw an exception if you try to use something else.

When you create new script, just start writing your code. There is nothing else you need. You can use anything you want in your scripts.

If you run script that is located in application/scripts and you need to use some class in module, then you'll have to manually register module with Application::registerModule() method so you can actually include the classes from there.

How to run the script in CLI env?

To run the script, you need to execute public/cli.php and you need to pass the script name you want to execute as parameter.

Example: if you have script located on application/scripts/backup-news.php, then you need to run:

cd /path/to/your-project/public
php cli.php backup-news

If you're running your script as CRON job, then you'll probably need to define something like this in your CRON rules:

/usr/bin/php /path/to/your-project/public/cli.php backup-news

If you want to run the script in module, then call your script with this pattern:

php cli.php [module_name]:[script_name]

Example: If you have module named "news" and "backup-news" script it located under the "news" module on application/modules/news/scripts/backup-news.php, then you can execute that script with:

php cli.php news:backup-news

Passing additional parameter(s)

If you need to pass additional parameter to your script, then feel free to add anything you need in any format you want - but only after the script name you're executing.

There is Cli class in Koldy framework that can help you easily fetch the parameters you passed to the script.

Example: if you run your script as this:

php cli.php backup-news --my-parameter="this is cool"

Then you can fetch the value of your parameter with:

Cli::getParameter('my-parameter'); // it will return "this is cool"

Heads up!
Cli class has some other useful methods you can use. Check the PHPdoc to see what else can Cli class do.