How can I create commands like Laravel artisan?

I want to create my own framework in PHP which allow me to create rest APIs more easily.

I want add some commands like in Laravel. For example in Laravel we write

php artisan make:controller

and it creates a controller. I want to make it so I can type

php <name_of_my_framework> make:gateway 

and it will create GateWay.php file and add class and namespaces in it. How can I make this logic?