PHP code example of jesobreira / cmdline

1. Go to this page and download the library: Download jesobreira/cmdline 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/ */

    

jesobreira / cmdline example snippets


use CmdLine\Parser as cmdline;

echo cmdline::get('color');

if (cmdline::keyexists('givemecoffee')) {
	echo "You want coffee.";
} else {
	echo "You do not want coffee.";
}

echo "You want: ";

if (cmdline::flagenabled('C')) echo "coffee ";

if (cmdline::flagenabled('B')) echo "beer ";

echo " and you do not want: ";

if (cmdline::flagdisabled('V')) echo "vodka ";

if (cmdline::flagdisabled('W')) echo "wine ";

echo " but you did not tell me if you want: ";

if (!cmdline::flagexists('S')) echo "soda ";

if (!cmdline::flagexists('J')) echo "juice ";

// 0 = php executable; 1 = php script; 2... = args
$first_argument = cmdline::getvalbyindex(2, false);
if (!$first_argument) {
	echo "You did not specify any argument.";
} else {
	echo "First argument is: " . $first_argument;
}


$user_wants = cmdline::get('iwant', 'nothing');
echo "You want" . $user_wants;