1. Go to this page and download the library: Download d0riven/php-flags 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/ */
d0riven / php-flags example snippets
use PhpFlags\Parser;
use PhpFlags\Spec\ApplicationSpec;
// example ping
$spec = ApplicationSpec::create();
$spec->version('1.0.0')->clearShort();
$count = $spec->flag('count')->short('c')->default(-1)
->desc('Number of times to send an ICMP request. The default of -1 sends an unlimited number of requests.')
->validRule(function($count) {
return $count >= -1;
})
->int('request count');
$timeout = $spec->flag('timeout')->short('t')->default(5)
->desc('Timeout seconds for ICMP requests.')
->validRule(function($timeout) {
return $timeout >= 0;
})
->int('request count');
$verbose = $spec->flag('verbose')->short('v')
->desc('verbose output.')
->bool();
$host = $spec->arg()
->desc('IP of the host for the ICMP request.')
->validRule(function($ip){
return preg_match('/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/', $ip);
})
->string('host');
try {
Parser::create($spec)->parse($argv);
} catch (PhpFlags\InvalidArgumentsException $e) {
echo $e->getMessage(), PHP_EOL;
exit(1);
} catch (PhpFlags\InvalidSpecException $e) {
echo $e->getMessage(), PHP_EOL;
exit(1);
}
echo " count: ", $count->get(), PHP_EOL;
echo "timeout: ", $timeout->get(), PHP_EOL;
echo "verbose: ", $verbose->get() ? 'true' : 'false', PHP_EOL;
echo " host: ", $host->get(), PHP_EOL;