<?php error_reporting(-1); require_once __DIR__ . '/vendor/autoload.php'; $args = new cli\Arguments(array('flags' => array('verbose' => array('description' => 'Turn on verbose mode', 'aliases' => array('v')), 'c' => array('description' => 'A counter to test stackable', 'stackable' => true)), 'options' => array('user' => array('description' => 'Username for authentication', 'aliases' => array('u'))), 'strict' => true)); try { $args->parse(); } catch (cli\InvalidArguments $e) { echo $e->getMessage() . "\n\n"; } print_r($args->getArguments());
<?php /** * Sample invocations: * * # php example_args.php -vC ./ --version * {"verbose":true,"cache":".\/","version":true} * # php example_args.php -vC --version * PHP Warning: [cli\Arguments] no value given for -C * # php example_args.php -vC multi word --version * {"verbose":true,"cache":"multi word","version":true} * */ require 'common.php'; $strict = in_array('--strict', $_SERVER['argv']); $arguments = new \cli\Arguments(compact('strict')); $arguments->addFlag(array('verbose', 'v'), 'Turn on verbose output'); $arguments->addFlag('version', 'Display the version'); $arguments->addFlag(array('quiet', 'q'), 'Disable all output'); $arguments->addFlag(array('help', 'h'), 'Show this help screen'); $arguments->addOption(array('cache', 'C'), array('default' => getcwd(), 'description' => 'Set the cache directory')); $arguments->addOption(array('name', 'n'), array('default' => 'James', 'description' => 'Set a name with a really long description and a default so we can see what line wrapping looks like which is probably a goo idea')); $arguments->parse(); if ($arguments['help']) { echo $arguments->getHelpScreen(); echo "\n\n"; } echo $arguments->asJSON() . "\n";
$files = array(__DIR__ . '/../../vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/../../../../autoload.php', __DIR__ . '/../vendor/autoload.php'); $found = false; foreach ($files as $file) { if (file_exists($file)) { require_once $file; break; } } if (!class_exists('Composer\\Autoload\\ClassLoader', false)) { die('You need to set up the project dependencies using the following commands:' . PHP_EOL . 'curl -s http://getcomposer.org/installer | php' . PHP_EOL . 'php composer.phar install' . PHP_EOL); } //------------------------------------ cli\Colors::enable(); $strict = in_array('--strict', $_SERVER['argv']); $arguments = new cli\Arguments(compact('strict')); $arguments->addOption(array('region'), ['description' => 'The AWS region to use']); $arguments->addOption(array('table'), ['description' => 'The DynamoDB table to use']); $arguments->addOption(array('key'), ['description' => 'The AWS key to use']); $arguments->addOption(array('secret'), ['description' => 'The AWS secret to use']); $arguments->addOption(array('ttl'), ['description' => "The number of milliseconds to leave a job before it's removed during a cleanup"]); $arguments->addFlag(array('create'), 'Create the table in DynamoDB'); $arguments->addFlag(array('cleanup'), 'Cleanup the table in DynamoDB'); $arguments->addFlag(array('v'), 'Set the system log level to Debug'); $arguments->parse(); //------------------------------------ // Setup Logging use Monolog\Logger; use Monolog\Handler\StreamHandler; use Monolog\Formatter\LineFormatter; if ($arguments['v']) {
#!/usr/bin/env php <?php require_once __DIR__ . "/../vendor/autoload.php"; $arguments = new \cli\Arguments(); $arguments->addFlag(array('help', 'h'), 'Show this help screen'); $arguments->addOption(['template', 't'], ['description' => 'Input template']); $arguments->addOption(['context', 'c'], ['description' => 'Input context']); $arguments->addOption(['write', 'w'], ['description' => 'Write output to file']); $arguments->parse(); if ($arguments['help']) { echo $arguments->getHelpScreen(); echo "\n\n"; exit; } $templatr = \Templatr\Templatr::fromArray($arguments); $templatr->render();
/** * Retrieve arguments from global to prepare them for further use. * * @param CommandEvent $event The Composer event fired to retrieve arguments from * * @author Benjamin Carl <*****@*****.**> * @return boolean|null TRUE on success, otherwise FALSE * @access protected * @static */ protected static function initArguments(CommandEvent $event = null) { // Check for retrieving arguments from Composer event ... if ($event !== null) { $arguments = $event->getArguments(); } else { $arguments = $_SERVER['argv']; } // Check for strict mode $strict = in_array('--strict', $arguments); $arguments = new \cli\Arguments(compact('strict'), $arguments); $arguments->addFlag(array('verbose', 'v'), 'Turn on verbose output'); $arguments->addFlag(array('version', 'V'), 'Display the version'); $arguments->addFlag(array('quiet', 'q'), 'Disable all output'); $arguments->addFlag(array('help', 'h'), 'Show this help screen'); // Parse the arguments $arguments->parse(); // Store arguments ... self::$arguments = $arguments; if (isset(self::$arguments['help']) === true) { self::showHelp(); } }
include $config['html_dir'] . "/includes/functions.inc.php"; //var_dump(cli_is_piped()); $scriptname = basename($argv[0]); $cli = TRUE; $localhost = get_localhost(); print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WTest Alert Notification%n\n", 'color'); print_versions(); // Allow the URL building code to build URLs with proper links. $_SESSION['userlevel'] = 10; if ($options['a']) { if ($config['alerts']['disable']['all']) { print_warning("All alert notifications disabled in config \$config['alerts']['disable']['all'], ignore it for testing!"); $config['alerts']['disable']['all'] = FALSE; } $alert_rules = cache_alert_rules(); $alert_assoc = cache_alert_assoc(); $sql = "SELECT * FROM `alert_table`"; $sql .= " WHERE `alert_table_id` = ?"; $entry = dbFetchRow($sql, array($options['a'])); //print_r($entry); alert_notifier($entry); } else { print_cli("\nUSAGE:\n{$scriptname} -a alert_entry [-d debug]\n", 'color'); $arguments = new \cli\Arguments(); $arguments->addFlag('d', 'Turn on debug output'); $arguments->addFlag('dd', 'More verbose debug output'); $arguments->addOption('a', array('default' => '<alert entry id>', 'description' => 'Send test notification to for an alert entry')); echo $arguments->getHelpScreen(); echo PHP_EOL . PHP_EOL; } // EOF
<?php /** * Sample invocations: * * # php example_args.php -vC ./ --version * {"verbose":true,"cache":".\/","version":true} * # php example_args.php -vC --version * PHP Warning: [cli\Arguments] no value given for -C * # php example_args.php -vC multi word --version * {"verbose":true,"cache":"multi word","version":true} * */ require 'common.php'; $strict = in_array('--strict', $_SERVER['argv']); if ($strict) { unset($_SERVER['argv'][array_search("--strict", $_SERVER['argv'])]); } $arguments = new \cli\Arguments(compact('strict')); $arguments->addFlag(array('verbose', 'v'), 'Turn on verbose output'); $arguments->addFlag('version', 'Turn on verbose output'); $arguments->addFlag(array('quiet', 'q'), 'Disable all output'); $arguments->addOption(array('cache', 'C'), array('default' => __DIR__, 'description' => 'Set the cache directory. Defaults to the current directory')); $arguments->addOption(array('name', 'n'), array('default' => null, 'description' => 'Set a name.')); $arguments->parse(); echo $arguments->asJSON() . "\n";