Skip to content

Instantly share code, notes, and snippets.

@unicodeveloper
Last active October 1, 2015 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unicodeveloper/2e23d64e18e5d59f1e7c to your computer and use it in GitHub Desktop.
Save unicodeveloper/2e23d64e18e5d59f1e7c to your computer and use it in GitHub Desktop.
Cab file: Example code to show how to write CLI Scripts
#!/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