PHP code example of xy2z / cliclass

1. Go to this page and download the library: Download xy2z/cliclass library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xy2z / cliclass example snippets




use xy2z\CliClass\CliClass;

class Router {
	/**
	 * Says hello world.
	 */
	public function hello_world() {
		echo 'Hello world.';
	}

	/**
	 * Says hello to $name.
	 */
	public function hello(string $name) {
		echo 'Hello ' . $name;
	}
}

CliClass::init($argv, [
	Router::class,
]);

bash
$ php cli.php
Usage:
 command [arguments]

Available commands:
 hello_world  Says hello world.
 hello        <string $name> Says hello to $name.
bash
$ php cli.php hello_world
Hello world.
bash
$ php cli.php hello
Usage: hello <string $name>
Error: Missing argument 2 for $name (no default value)
bash
$ php cli.php hello Peter
Hello Peter