Turn any PHP class into cli commands

How to turn any PHP class into cli commands without writing a line of code? Use cli-maker and you won't have to write any additional code, just simple config array.

Cli-maker is powerful and easy to use library that allows you to generate cli commands from given PHP classes. Before we move forward you must be aware that cli-maker works only with PHP 7 and above.

Installation

composer require wilgucki/cli-maker

Usage

Create on root level of your application cli-maker.php file. Future version of this library will allow you to choose location of this file.

Add all class names you want to access from command line into this file. Currently library requires all class names to be unique (even if classes are using different namespaces). This will change in future version.

<?php
// cli-maker.php

return [
    \App\Namespace\Foo::class,
    \App\Another\Namespace\Bar::class,
];

To list all available commands run ./vendor/bin/cli-maker.

To run single command simply add it after cli-maker script.

./vendor/bin/cli-maker foo:bar

If converted method accepts parameters, you can add them in the same order as they were defined in your method. If you want to check those parameters you can use --help option.

./vendor/bin/cli-maker foo:bar --help

Last but not least. This is the very first version of cli-maker. Hence you will see rapid improvements in next weeks. It would be great if you would leave feedback.

Cli-maker on Github.