getOption() публичный Метод

If the option accepts a value, the value set for that option is returned. If no value was set with {@link setOption()}, the default value of the option is returned.j If the option accepts no value, the method returns true if the option was set and false otherwise.
public getOption ( string $name ) : mixed
$name string The long or short option name.
Результат mixed The option value or `true`/`false` for options without values.
 private function createRunner(Args $args)
 {
     if ($args->getOption('dry-run')) {
         return new DryRunner($this->style, $this->config, !$args->getOption('all'));
     }
     return new VerboseRunner($this->style, $this->config, !$args->getOption('all'));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function getCommandFrom($className)
 {
     if (class_exists($className)) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $reflector = new \ReflectionClass($className);
         $instance = $reflector->newInstanceWithoutConstructor();
         foreach ($reflector->getProperties() as $property) {
             if ($instance instanceof ConsoleCommandInterface && $property->getName() == 'io') {
                 continue;
             }
             if (!$this->format->hasArgument($property->getName()) && !$this->format->hasOption($property->getName())) {
                 throw new \InvalidArgumentException(sprintf("There is not '%s' argument defined in the %s command", $property->getName(), $className));
             }
             $value = null;
             if ($this->format->hasArgument($property->getName())) {
                 $value = $this->args->getArgument($property->getName());
             } elseif ($this->format->hasOption($property->getName())) {
                 $value = $this->args->getOption($property->getName());
             }
             $accessor->setValue($instance, $property->getName(), $value);
         }
         return $instance;
     }
     return;
 }
Пример #3
0
 /**
  * Handles the "package --add" command.
  *
  * @param Args $args The console arguments.
  *
  * @return int The status code.
  */
 public function handleAdd(Args $args)
 {
     $packageName = $args->getArgument('name');
     $installPath = Path::makeAbsolute($args->getArgument('path'), getcwd());
     $installer = $args->getOption('installer');
     $this->packageManager->installPackage($installPath, $packageName, $installer);
     return 0;
 }
Пример #4
0
 /**
  * Handles the "package --install" command.
  *
  * @param Args $args The console arguments.
  *
  * @return int The status code.
  */
 public function handleInstall(Args $args)
 {
     $packageName = $args->getArgument('name');
     $installPath = Path::makeAbsolute($args->getArgument('path'), getcwd());
     $installer = $args->getOption('installer');
     $env = $args->isOptionSet('dev') ? Environment::DEV : Environment::PROD;
     $this->packageManager->installPackage($installPath, $packageName, $installer, $env);
     return 0;
 }
Пример #5
0
 /**
  * handle.
  *
  * @param Args $args
  * @param IO   $io
  *
  * @return int
  */
 public function handle(Args $args, IO $io)
 {
     $configFileExist = true;
     $overwrite = is_string($args->getOption('force'));
     try {
         $this->configurationLoader->setRootDirectory($args->getOption('config'));
         $configuration = $this->configurationLoader->loadConfiguration();
     } catch (ConfigurationLoadingException $e) {
         $configFileExist = false;
     }
     if (!$configFileExist || $overwrite) {
         $configuration = ['urls' => ['google' => ['url' => 'https://www.google.fr', 'method' => 'GET', 'headers' => [], 'timeout' => 1, 'validator' => [], 'status_code' => 200, 'metric_uuid' => null, 'service_uuid' => null]], 'hogosha_portal' => ['username' => '', 'password' => '', 'base_uri' => 'http://localhost:8000/api/', 'metric_update' => false, 'incident_update' => false, 'default_failed_incident_message' => 'An error as occured, we are investigating %service_name%', 'default_resolved_incident_message' => 'The service %service_name% is back to normal']];
         // Dump configuration
         $content = $this->configurationDumper->dumpConfiguration($configuration);
         $this->filesystem->dumpFile($this->configurationLoader->getConfigurationFilepath(), $content);
         $io->writeLine('<info>Creating monitor file</info>');
     } else {
         $io->writeLine(sprintf('<info>You already have a configuration file in</info> "%s"', $this->configurationLoader->getConfigurationFilepath()));
     }
 }
Пример #6
0
 public function handleAdd(Args $args)
 {
     $descriptions = $args->getOption('description');
     $parameters = array();
     // The first description is for the installer
     $description = $descriptions ? array_shift($descriptions) : null;
     foreach ($args->getOption('param') as $parameter) {
         // Subsequent descriptions are for the parameters
         $paramDescription = $descriptions ? array_shift($descriptions) : null;
         // Optional parameter with default value
         if (false !== ($pos = strpos($parameter, '='))) {
             $parameters[] = new InstallerParameter(substr($parameter, 0, $pos), InstallerParameter::OPTIONAL, StringUtil::parseValue(substr($parameter, $pos + 1)), $paramDescription);
             continue;
         }
         // Required parameter
         $parameters[] = new InstallerParameter($parameter, InstallerParameter::REQUIRED, null, $paramDescription);
     }
     $this->installerManager->addRootInstallerDescriptor(new InstallerDescriptor($args->getArgument('name'), $args->getArgument('class'), $description, $parameters));
     return 0;
 }
Пример #7
0
 /**
  * handle.
  *
  * @param Args $args
  * @param IO   $io
  *
  * @return int
  */
 public function handle(Args $args, IO $io)
 {
     $this->configurationLoader->setRootDirectory($args->getOption('config'));
     $config = $this->configurationLoader->loadConfiguration();
     try {
         $urlProvider = new UrlProvider($config);
         $runner = new Runner($urlProvider, GuzzleClient::createClient($io));
         $renderer = RendererFactory::create($args->getOption('format'), $io);
         $results = $runner->run();
         $renderer->render($results);
         if (isset($config['hogosha_portal']['metric_update']) || isset($config['hogosha_portal']['incident_update'])) {
             $pusher = new PusherManager($config, $io);
             $pusher->push($results);
         }
     } catch (BadResponseException $e) {
         $io->writeLine(sprintf('<error>Exception:</error> "%s"', $e->getMessage()));
     } catch (ConfigurationLoadingException $e) {
         $io->writeLine(sprintf('<info>There is no configuration file in</info> "%s"', $this->configurationLoader->getRootDirectory()));
     }
 }
Пример #8
0
 /**
  * Returns the non-root modules selected in the console arguments.
  *
  * @param Args       $args    The console arguments
  * @param ModuleList $modules The available modules
  *
  * @return string[] The module names
  */
 public static function getModuleNamesWithoutRoot(Args $args, ModuleList $modules)
 {
     // Display all modules if "all" is set
     if ($args->isOptionSet('all')) {
         return $modules->getInstalledModuleNames();
     }
     $moduleNames = array();
     foreach ($args->getOption('module') as $moduleName) {
         $moduleNames[] = $moduleName;
     }
     return $moduleNames ?: $modules->getInstalledModuleNames();
 }
Пример #9
0
 /**
  * Returns the non-root packages selected in the console arguments.
  *
  * @param Args              $args     The console arguments.
  * @param PackageCollection $packages The available packages.
  *
  * @return string[] The package names.
  */
 public static function getPackageNamesWithoutRoot(Args $args, PackageCollection $packages)
 {
     // Display all packages if "all" is set
     if ($args->isOptionSet('all')) {
         return $packages->getInstalledPackageNames();
     }
     $packageNames = array();
     foreach ($args->getOption('package') as $packageName) {
         $packageNames[] = $packageName;
     }
     return $packageNames ?: $packages->getInstalledPackageNames();
 }
Пример #10
0
 /**
  * Handles the "find" command.
  *
  * @param Args $args The console arguments.
  * @param IO   $io   The I/O.
  *
  * @return int The status code.
  */
 public function handle(Args $args, IO $io)
 {
     $criteria = array();
     if ($args->isOptionSet('path')) {
         $criteria['path'] = $args->getOption('path');
         $criteria['language'] = $args->getOption('language');
     }
     if ($args->isOptionSet('name')) {
         if (isset($criteria['path'])) {
             throw new RuntimeException('The options --name and --path cannot be combined.');
         }
         $criteria['path'] = '/**/' . $args->getOption('name');
         $criteria['language'] = $args->getOption('language');
     }
     if ($args->isOptionSet('class')) {
         $criteria['class'] = $args->getOption('class');
     }
     if ($args->isOptionSet('type')) {
         $criteria['bindingType'] = $args->getOption('type');
     }
     if (!$criteria) {
         throw new RuntimeException('No search criteria specified.');
     }
     return $this->listMatches($io, $criteria);
 }
Пример #11
0
 public function handle(Args $args, IO $io, Command $command)
 {
     $tabular = Tabular::getInstance();
     $dom = new \DOMDocument('1.0');
     $dom->load($args->getArgument('xml'));
     $tableDom = $tabular->tabulate($dom, $args->getArgument('definition'));
     if ($args->getOption('debug')) {
         $io->writeLine($tableDom->saveXml());
     }
     $rows = $tableDom->toArray();
     $table = new Table(TableStyle::solidBorder());
     $table->setHeaderRow(array_keys(reset($rows) ?: array()));
     foreach ($rows as $row) {
         $table->addRow($row);
     }
     $table->render($io);
 }
Пример #12
0
 public function handle(Args $args, IO $io, Command $command)
 {
     $table = new Table();
     $table->setHeaderRow(array('Name', 'Description'));
     $output = new ConsoleOutput();
     $style = new OutputFormatterStyle('white', 'black', array('bold'));
     if ($args->getArgument('package') == '') {
         $output->writeln(Cpm\message::USAGE);
         exit;
     }
     $limit = $args->getOption('limit');
     $limit_str = $limit ? 'limit ' . $limit : '';
     $q = $args->getArgument('package');
     $datas = R::findAll('repo', ' name LIKE ? order by download_monthly desc,favers desc,download_total desc' . $limit_str, ['%' . $q . '%']);
     foreach ($datas as $data) {
         $output->getFormatter()->setStyle('bold', $style);
         //            $output->writeln('<bold>'.$data->name.'</>'.' '.$data->description);
         //            $output->writeln($data->keywords);
         $table->addRow(array("(" . $data->favers . ")" . $data->name, $data->description));
     }
     $table->render($io);
     return 0;
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function getOption($name)
 {
     return $this->args ? $this->args->getOption($name) : null;
 }
Пример #14
0
 public function handleUpdate(Args $args)
 {
     $flags = $args->isOptionSet('force') ? AssetManager::OVERRIDE | AssetManager::IGNORE_SERVER_NOT_FOUND : AssetManager::OVERRIDE;
     $mappingToUpdate = $this->getMappingByUuidPrefix($args->getArgument('uuid'));
     $path = $mappingToUpdate->getGlob();
     $serverPath = $mappingToUpdate->getServerPath();
     $serverName = $mappingToUpdate->getServerName();
     if ($args->isOptionSet('path')) {
         $path = Path::makeAbsolute($args->getOption('path'), $this->currentPath);
     }
     if ($args->isOptionSet('server-path')) {
         $serverPath = $args->getOption('server-path');
     }
     if ($args->isOptionSet('server')) {
         $serverName = $args->getOption('server');
     }
     $updatedMapping = new AssetMapping($path, $serverName, $serverPath, $mappingToUpdate->getUuid());
     if ($this->mappingsEqual($mappingToUpdate, $updatedMapping)) {
         throw new RuntimeException('Nothing to update.');
     }
     $this->assetManager->addRootAssetMapping($updatedMapping, $flags);
     return 0;
 }
Пример #15
0
 /**
  * Handles the "puli map --update" command.
  *
  * @param Args $args The console arguments.
  *
  * @return int The status code.
  */
 public function handleUpdate(Args $args)
 {
     $flags = $args->isOptionSet('force') ? RepositoryManager::OVERRIDE | RepositoryManager::IGNORE_FILE_NOT_FOUND : RepositoryManager::OVERRIDE;
     $repositoryPath = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
     $mappingToUpdate = $this->repoManager->getRootPathMapping($repositoryPath);
     $pathReferences = array_flip($mappingToUpdate->getPathReferences());
     foreach ($args->getOption('add') as $pathReference) {
         $pathReferences[$pathReference] = true;
     }
     foreach ($args->getOption('remove') as $pathReference) {
         unset($pathReferences[$pathReference]);
     }
     if (0 === count($pathReferences)) {
         $this->repoManager->removeRootPathMapping($repositoryPath);
         return 0;
     }
     $updatedMapping = new PathMapping($repositoryPath, array_keys($pathReferences));
     if ($this->mappingsEqual($mappingToUpdate, $updatedMapping)) {
         throw new RuntimeException('Nothing to update.');
     }
     $this->repoManager->addRootPathMapping($updatedMapping, $flags);
     return 0;
 }
Пример #16
0
 private function parseUnsetParams(Args $args, array &$bindingParams)
 {
     foreach ($args->getOption('unset-param') as $parameter) {
         unset($bindingParams[$parameter]);
     }
 }
Пример #17
0
 /**
  * @param Args         $args
  * @param ClassBinding $bindingToUpdate
  *
  * @return ClassBinding
  */
 private function getUpdatedClassBinding(Args $args, ClassBinding $bindingToUpdate)
 {
     $className = $bindingToUpdate->getClassName();
     $typeName = $bindingToUpdate->getTypeName();
     $bindingParams = $bindingToUpdate->getParameterValues();
     if ($args->isOptionSet('class')) {
         $className = $args->getOption('class');
     }
     if ($args->isOptionSet('type')) {
         $typeName = $args->getOption('type');
     }
     $this->parseParams($args, $bindingParams);
     $this->unsetParams($args, $bindingParams);
     return new ClassBinding($className, $typeName, $bindingParams, $bindingToUpdate->getUuid());
 }
Пример #18
0
 private function unsetParams(Args $args, array &$parameters)
 {
     foreach ($args->getOption('unset-param') as $parameter) {
         unset($parameters[$parameter]);
     }
 }
Пример #19
0
 private function parseUnsetParams(Args $args, array &$bindingParams, array &$paramDescriptions)
 {
     foreach ($args->getOption('unset-param') as $parameterName) {
         unset($bindingParams[$parameterName]);
         unset($paramDescriptions[$parameterName]);
     }
 }
Пример #20
0
 public function testSetOptionCastsValueToArrayIfMultiValued()
 {
     $format = ArgsFormat::build()->addOption(new Option('option', 'o', Option::REQUIRED_VALUE | Option::INTEGER | Option::MULTI_VALUED))->getFormat();
     $args = new Args($format);
     $args->setOption('option', '1');
     $this->assertSame(array(1), $args->getOption('option'));
     $this->assertSame(array(1), $args->getOption('o'));
 }