private function getopt() { $getopt = new Getopt([(new Option('h', 'help', Getopt::NO_ARGUMENT))->setDescription('Show this help'), (new Option('d', 'default', Getopt::NO_ARGUMENT))->setDescription('Get Default config in json mode'), (new Option('r', 'reload', Getopt::NO_ARGUMENT))->setDescription('Reload workers'), (new Option('D', 'daemon', Getopt::NO_ARGUMENT))->setDescription('Daemonize'), (new Option('c', 'config', Getopt::OPTIONAL_ARGUMENT))->setDefaultValue(false)->setDescription('Set custom config file')->setArgument(new Argument(null, null, 'file path')), (new Option('v', 'verbose', Getopt::NO_ARGUMENT))->setDescription('Increase verbosity'), (new Option('V', 'version', Getopt::NO_ARGUMENT))->setDescription('Get version')]); $getopt->parse(); if ($getopt->getOption('h')) { echo $getopt->getHelpText(30); exit(0); } if ($getopt->getOption('V')) { echo "LVMCloud Core Worker\nVersion: " . Server::VERSION . PHP_EOL; exit(0); } if ($getopt->getOption('r')) { $this->getConfig(); $rel = $this->reload_extern(); if ($rel !== true) { echo $rel . PHP_EOL; } exit(0); } if ($getopt->getOption('D')) { $this->daemon = true; } if ($getopt->getOption('d')) { $this->getDefaults(); exit(0); } $loglevel = is_null($getopt->getOption('v')) ? 0 : $getopt->getOption('v'); $config = is_null($getopt->getOption('c')) || is_numeric($getopt->getOption('c')) ? false : realpath($getopt->getOption('c')); $this->setConsoleLogLevel($loglevel); if ($config) { $this->setConfigFile($config); } }
/** * Parse the options. */ public function parse_options() { $getopt = new Getopt([['d', 'directory', Getopt::REQUIRED_ARGUMENT, 'Run under given directory'], ['l', 'level', Getopt::REQUIRED_ARGUMENT, 'Practice level on epic'], ['s', 'skip', Getopt::NO_ARGUMENT, 'Skip user input'], ['t', 'time', Getopt::REQUIRED_ARGUMENT, 'Delay each turn by seconds'], ['L', 'locale', Getopt::REQUIRED_ARGUMENT, 'Specify locale like en_US'], ['h', 'help', Getopt::NO_ARGUMENT, 'Show this message']]); try { $getopt->parse(); } catch (\Exception $e) { echo $e->getMessage() . "\n"; exit; } if ($getopt->getOption('h')) { echo $getopt->getHelpText(); exit; } if ($getopt->getOption('d')) { Config::$path_prefix = $getopt->getOption('d'); } if ($getopt->getOption('l')) { Config::$practice_level = $getopt->getOption('l'); } if ($getopt->getOption('s')) { Config::$skip_input = true; } if (!is_null($getopt->getOption('t'))) { Config::$delay = $getopt->getOption('t'); } // get locale from $LANG like en_US.UTF8 list(Config::$locale) = explode('.', getenv('LANG')); if ($getopt->getOption('L')) { Config::$locale = $getopt->getOption('L'); } }
public static function main() { // manage the command line options $getopt = new Getopt(array((new Option(null, 'version', Getopt::NO_ARGUMENT))->setDescription('Display the current version'), (new Option(null, 'nomail', Getopt::NO_ARGUMENT))->setDescription('Do not send report email'), (new Option(null, 'csvfile', Getopt::REQUIRED_ARGUMENT))->setDescription('Use the specified path as csv input file'))); try { $getopt->parse(); if ($getopt->getOption('version') > 0) { echo "SotaImport version: " . Cli::VERSION . "\r\n"; exit(1); } $nomail = $getopt->getOption('nomail'); $csvfile = $getopt->getOption('csvfile'); } catch (\UnexpectedValueException $e) { echo "Error: " . $e->getMessage() . "\n"; echo $getopt->getHelpText(); exit(1); } $csvImport = new CsvImport(); if ($nomail > 0) { $csvImport->setSendMail(false); } if (isset($csvfile) && $csvfile != '') { $csvImport->setCsvFilePath($csvfile); } $csvImport->execute(); }
function retrieve_args() { $opt = new Getopt([(new Option('h', 'help'))->setDescription('Prints this help'), (new Option('v', 'verbose'))->setDescription('Verbose output'), (new Option('f', 'file-title'))->setDescription('Use file name for title tag'), (new Option('x', 'sort-lex'))->setDescription('Sort files lexicographically'), (new Option('t', 'tree-dst'))->setDescription('Retain the tree structure of the source album at destination'), (new Option('p', 'drop-dst'))->setDescription('Do not create destination directory'), (new Option('r', 'reverse'))->setDescription('Copy files in reverse order (last file first)'), (new Option('e', 'file-type', Getopt::REQUIRED_ARGUMENT))->setDescription('Accept only audio files of the specified type'), (new Option('u', 'unified-name', Getopt::REQUIRED_ARGUMENT))->setDescription('Base name for everything but the "Artist" tag'), (new Option('b', 'album-num', Getopt::REQUIRED_ARGUMENT))->setDescription('Album number'), (new Option('a', 'artist-tag', Getopt::REQUIRED_ARGUMENT))->setDescription('"Artist" tag'), (new Option('g', 'album-tag', Getopt::REQUIRED_ARGUMENT))->setDescription('"Album" tag')]); $opt->parse(); if ($opt->getOption('help')) { print $opt->getHelpText(); exit(2); } if (count($opt->getOperands()) !== 2) { print "Command line syntax: <src> and <dst> operands required.\n" . $opt->getHelpText(); exit(2); } if (!is_dir($opt->getOperand(0))) { print "Source directory \"{$opt->getOperand(0)}\" is not there.\n"; exit(2); } if (!is_dir($opt->getOperand(1))) { print "Destination path \"{$opt->getOperand(1)}\" is not there.\n"; exit(2); } return $opt; }
require __DIR__ . '/helper.php'; //require __DIR__ . '/asana.php'; use Ulrichsg\Getopt\Getopt; use Ulrichsg\Getopt\Option; $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH); $getopt = new Getopt(array( (new Option('r', 'refresh_token'))->setDescription('Refresh token if exists'), (new Option('d', 'remove'))->setDescription('Remove credentials to authorize new user'), (new Option('v', 'version', Getopt::NO_ARGUMENT))->setDescription('Display version information') )); try { $getopt->parse(); if ($getopt->getOption('v')) { logMessage(VERSION); closeSession(false); } if ($getopt->getOption('refresh_token')) { refreshTokenCli(); closeSession(false); } if ($getopt->getOption('remove')) { removeCredentials(); closeSession(false); } } catch (UnexpectedValueException $e) {
use Ulrichsg\Getopt\Option; if (php_sapi_name() !== 'cli') { echo 'This Script must be run in a CLI.'; exit; } if (strpos(__DIR__, 'vendor') === false) { // We are in a local development $vendorDirectory = __DIR__ . '/../../vendor/'; } else { // We are in vendor directory $vendorDirectory = __DIR__ . '/../../../../'; } require_once $vendorDirectory . 'autoload.php'; $getOpt = new Getopt(array(new Option('e', 'entity', Getopt::REQUIRED_ARGUMENT), new Option('f', 'file', Getopt::OPTIONAL_ARGUMENT), new Option(null, 'regenerate', Getopt::OPTIONAL_ARGUMENT), new Option(null, 'clean', Getopt::OPTIONAL_ARGUMENT), new Option(null, 'help', Getopt::NO_ARGUMENT), new Option(null, 'version', Getopt::NO_ARGUMENT))); $getOpt->parse(); if ($getOpt->getOption('help')) { echo $getOpt->getHelpText(); } else { if ($getOpt->getOption('version')) { echo 'Version ' . \OpenLdapObject\OpenLdapObject::VERSION . ' (' . \OpenLdapObject\OpenLdapObject::DATE . ')' . PHP_EOL; } else { if ($getOpt->getOption('entity')) { if ($getOpt->getOption('regenerate')) { $command = new \OpenLdapObject\Command\ReGenerateCommand($getOpt->getOptions()); } elseif ($getOpt->getOption('clean')) { $command = new \OpenLdapObject\Command\CleanCommand($getOpt->getOptions()); } else { $command = new \OpenLdapObject\Command\GenerateCommand($getOpt->getOptions()); } $command->exec(); } else {
if (is_dir($path)) { $realIndex = $path . '/index.php'; } elseif (is_file($path)) { if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') { return false; } $realIndex = $path; } } // Try to find and load composer autoloader $vendorPaths = [realpath(__DIR__ . '/vendor/autoload.php'), realpath(__DIR__ . '/../vendor/autoload.php'), realpath(__DIR__ . '/../../vendor/autoload.php'), realpath(__DIR__ . '/../../../vendor/autoload.php'), realpath(__DIR__ . '/../../../../vendor/autoload.php'), realpath(__DIR__ . '/../../../../../vendor/autoload.php'), realpath('./vendor/autoload.php')]; foreach ($vendorPaths as $vendorPath) { if ($vendorPath && file_exists($vendorPath)) { require_once $vendorPath; break; } } // Parse additional options $cliOptions = new Getopt([[null, 'index', Getopt::OPTIONAL_ARGUMENT], [null, 'cov-src', Getopt::OPTIONAL_ARGUMENT], [null, 'cov-xml', Getopt::OPTIONAL_ARGUMENT], [null, 'cov-cov', Getopt::OPTIONAL_ARGUMENT], [null, 'cov-html', Getopt::OPTIONAL_ARGUMENT]]); $cliOptions->parse(getenv('PHPUNINT_ARGUMENTS')); $realIndex = isset($realIndex) ? $realIndex : realpath($cliOptions->getOption('index')); if (class_exists('\\JBZoo\\PHPUnit\\CovCatcher') && !(Sys::isPHP7() && Sys::hasXdebug())) { $testname = (new Data($_REQUEST))->get('testname'); $coverHash = md5(implode('||', [serialize($_REQUEST), serialize($_SERVER), PHP_VERSION])); $coverHash = $testname ? $testname . '-' . $coverHash : $testname; $covCatcher = new CovCatcher($coverHash, ['src' => $cliOptions->getOption('cov-src'), 'xml' => $cliOptions->getOption('cov-xml'), 'cov' => $cliOptions->getOption('cov-cov'), 'html' => $cliOptions->getOption('cov-html')]); $result = $covCatcher->includeFile($realIndex); } else { $result = (require_once $realIndex); } return $result;