-
-
Save unicodeveloper/2e23d64e18e5d59f1e7c to your computer and use it in GitHub Desktop.
Cab file: Example code to show how to write CLI Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/** | |
* Message displayed to the console if the user supplies no command | |
* @return void | |
*/ | |
function helpMessage() | |
{ | |
echo " | |
______ ___ _______ __ _____ _____ | |
/ ____/___ ____ _/_/ ___ / _______/ / \ / ___/ /____/ | |
/ / / __ \/ __ \/ / / / / ______ / /_\ / / / /____ | |
/ /___/ /_/ / /_/ / /____/ / / /_____/ / ____ / /__/ /___/ | |
\____/\____/\____/\______/ /_/ /__/ \_/\___/\____/ | |
Usage: | |
command [options] [arguments] | |
Options: | |
--drive Drive the cab | |
install Install all the tools needed to drive the cab | |
"; | |
} | |
/** | |
* Checks if the arguments are valid and exist | |
* @param $arg | |
* @return void | |
*/ | |
function validateArgs($arg) | |
{ | |
if ( count($arg) == 1){ | |
helpMessage(); | |
return; | |
} | |
grabCommands($arg[1]); | |
} | |
/** | |
* Gets commands passed as arguments to the command line | |
* @param string $command | |
* @return void | |
*/ | |
function grabCommands($command) | |
{ | |
if( $command === 'install') { | |
echo " | |
......Installing | |
......gearbox, | |
......car handle, | |
......motor engine and spareparts | |
Done. Installed Successfully"; | |
} | |
if( $command === '--drive') { | |
echo "....The car is in motion now. Please Drive Carefully"; | |
} | |
} | |
validateArgs($argv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment