If the argument is not set, the default value configured in the argument
format is returned.
/** * {@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; }
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); }
private function getResolvedProfile(Args $args, IO $io) { $profileResolver = new AutomaticProfileResolver($this->config); if ($io->isInteractive()) { $profileResolver = new InteractiveProfileResolver($this->config, $this->style, $profileResolver); } return $this->profileConfigResolver->resolve($profileResolver->resolve($args->getArgument('profile'))->name); }
/** * Handles the "puli plugin --remove" command. * * @param Args $args The console arguments. * * @return int The status code. */ public function handleDelete(Args $args) { $pluginClass = $args->getArgument('class'); if (!$this->manager->hasPluginClass($pluginClass)) { throw new RuntimeException(sprintf('The plugin class "%s" is not installed.', $pluginClass)); } $this->manager->removePluginClass($pluginClass); return 0; }
public function handleDelete(Args $args) { $installerName = $args->getArgument('name'); if (!$this->installerManager->hasInstallerDescriptor($installerName)) { throw new RuntimeException(sprintf('The installer "%s" does not exist.', $installerName)); } $this->installerManager->removeRootInstallerDescriptor($installerName); return 0; }
/** * Handles the "tree" 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) { $path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath); $resource = $this->repo->get($path); $total = 0; $io->writeLine('<c1>' . $resource->getPath() . '</c1>'); $this->printTree($io, $resource, $total); $io->writeLine(''); $io->writeLine($total . ' resources'); return 0; }
/** * Handles the "add-prefix" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int Returns 0 on success and a positive integer on error. */ public function handle(Args $args, IO $io) { $prefix = rtrim($args->getArgument('prefix'), '\\'); $paths = $args->getArgument('path'); foreach ($paths as $path) { if (!$this->filesystem->isAbsolutePath($path)) { $path = getcwd() . DIRECTORY_SEPARATOR . $path; } if (is_dir($path)) { $this->finder->files()->name('*.php')->in($path); foreach ($this->finder as $file) { $this->scopeFile($file->getPathName(), $prefix, $io); } } if (!is_file($path)) { continue; } $this->scopeFile($path, $prefix, $io); } return 0; }
/** * @param Args $args * @param IO $io */ public function handle(Args $args, IO $io) { parent::parseConfig($io); try { $retriever = new Retriever(); $retriever->download($args->getArgument('url')); $io->writeLine('Downloaded and extracted'); } catch (\RuntimeException $e) { $io->errorLine('Invalid url'); exit; } }
/** * {@inheritdoc} */ public function handle(Args $args, IO $io, Command $command) { $application = $command->getApplication(); if ($args->isArgumentSet('command')) { $theCommand = $application->getCommand($args->getArgument('command')); $usage = new CommandHelp($theCommand); } else { $usage = new ApplicationHelp($application); } $usage->render($io); return 0; }
/** * Handles the "url" 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) { foreach ($args->getArgument('path') as $path) { if (!Glob::isDynamic($path)) { $this->printUrl($path, $io); continue; } foreach ($this->repo->find($path) as $resource) { $this->printUrl($resource->getPath(), $io); } } return 0; }
/** * Handles the "upgrade" 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) { $moduleFile = $this->moduleFileManager->getModuleFile(); $originVersion = $moduleFile->getVersion(); $targetVersion = $args->getArgument('version'); if (version_compare($originVersion, $targetVersion, '=')) { $io->writeLine(sprintf('Your puli.json is already at version %s.', $targetVersion)); return 0; } $this->moduleFileManager->migrate($targetVersion); $io->writeLine(sprintf('Migrated your puli.json from version %s to version %s.', $originVersion, $targetVersion)); return 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; }
/** * Handles the "ls" 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) { $path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath); $resource = $this->repo->get($path); if (!$resource->hasChildren()) { throw new RuntimeException(sprintf('The resource "%s" does not have children.', $resource->getPath())); } if ($args->isOptionSet('long')) { $this->listLong($io, $resource->listChildren()); } else { $this->listShort($io, $resource->listChildren()); } return 0; }
/** * {@inheritdoc} */ public function handle(Args $args, IO $io, Command $command) { $descriptor = new XmlDescriptor(); $output = new IOOutput($io); $application = $command->getApplication(); $applicationAdapter = new ApplicationAdapter($application); if ($args->isArgumentSet('command')) { $theCommand = $application->getCommand($args->getArgument('command')); $commandAdapter = new CommandAdapter($theCommand, $applicationAdapter); $descriptor->describe($output, $commandAdapter); } else { $descriptor->describe($output, $applicationAdapter); } return 0; }
/** * Handles the "ls" 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) { $path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath); $resources = $this->repo->find($path); if (!count($resources)) { $io->errorLine("No resources found for path {$path}"); return 1; } foreach ($resources as $resource) { if ($resource instanceof BodyResource) { $io->writeLine($resource->getBody()); } } return 0; }
public function handleShow(Args $args, IO $io) { $this->style->title('Show profile information'); if ($io->isVerbose()) { $this->style->text([sprintf('// Using config file: %s', $this->config->get('config_file', '')), sprintf('// Project directory: %s', $this->config->get('project_directory', '')), sprintf('// Dancer config directory: %s', $this->config->get('dancer_directory', ''))]); } $profileNames = array_keys($this->config->getProfiles()); if (!($profileName = $args->getArgument('name'))) { $profileName = $this->style->choice('Profile to show', $profileNames); } if (null === $profileName) { $this->style->error(sprintf('Unable to find a profile with name "%s".', $profileName)); return 1; } $this->style->section($profileName); $this->renderResolvedProfile($this->config->getProfiles()[$profileName], $io->isVerbose()); return 0; }
/** * Handles the "build" command. * * @param Args $args The console arguments. * * @return int The status code. */ public function handle(Args $args) { $target = $args->getArgument('target'); if (!in_array($target, self::$targets)) { throw new RuntimeException(sprintf('Invalid build target "%s". Expected one of: "%s"', $target, implode('", "', self::$targets))); } if ('all' === $target || 'factory' === $target) { $this->factoryManager->autoGenerateFactoryClass(); } if ('all' === $target || 'repository' === $target) { $this->repoManager->clearRepository(); $this->repoManager->buildRepository(); } if ('all' === $target || 'discovery' === $target) { $this->discoveryManager->clearDiscovery(); $this->discoveryManager->buildDiscovery(); } return 0; }
/** * @param Args $args * @param IO $io */ public function handle(Args $args, IO $io) { parent::parseConfig($io); try { $filesScanner = new Files\Scanner($args->getArgument('path')); $files = $filesScanner->scan(); } catch (\RuntimeException $e) { $io->errorLine("Invalid path"); exit; } try { $uploader = new Uploader(new Ftp($this->profile)); $uploader->upload($files); $io->writeLine("Uploaded"); } catch (\RuntimeException $e) { $io->errorLine($e->getMessage()); exit; } }
public function handle(Args $args, IO $io, Command $command) { $output = new ConsoleOutput(); $style = new OutputFormatterStyle('white', 'black', array('bold')); if ($args->getArgument('package') == '') { $output->writeln(Cpm\message::USAGE); exit; } if (!file_exists('composer.json')) { $output->writeln(Cpm\message::NOComposerJSON); } $json = file_get_contents('composer.json'); $array = json_decode($json, TRUE); $datas = $array['require']; foreach ($datas as $data) { $output->getFormatter()->setStyle('bold', $style); $output->writeln('<bold>' . $data->name . '</>' . ' ' . $data->description); $output->writeln($data->keywords); } return 0; }
private function getPageName(Application $application, Args $args) { if ($args->isArgumentSet('command')) { $command = $application->getCommand($args->getArgument('command')); return $this->commandPagePrefix . $command->getName(); } if ($this->applicationPage) { return $this->applicationPage; } return $application->getConfig()->getName(); }
/** * Handles the "puli type --delete" command. * * @param Args $args The console arguments. * * @return int The status code. */ public function handleDelete(Args $args) { $typeName = $args->getArgument('name'); if (!$this->discoveryManager->hasRootTypeDescriptor($typeName)) { throw new RuntimeException(sprintf('The type "%s" does not exist in the package "%s".', $typeName, $this->packages->getRootPackageName())); } $this->discoveryManager->removeRootTypeDescriptor($typeName); return 0; }
public function handleDelete(Args $args) { $serverName = $args->getArgument('name'); if (!$this->serverManager->hasServer($serverName)) { throw NoSuchServerException::forServerName($serverName); } $this->serverManager->removeServer($serverName); return 0; }
/** * {@inheritdoc} */ public function getArgument($name) { return $this->args ? $this->args->getArgument($name) : null; }
/** * Handles the "module --delete" command. * * @param Args $args The console arguments * * @return int The status code */ public function handleDelete(Args $args) { $moduleName = $args->getArgument('name'); if (!$this->moduleManager->hasModule($moduleName)) { throw new RuntimeException(sprintf('The module "%s" is not installed.', $moduleName)); } $this->moduleManager->removeModule($moduleName); return 0; }
/** * Handles the "package --delete" command. * * @param Args $args The console arguments. * * @return int The status code. */ public function handleDelete(Args $args) { $packageName = $args->getArgument('name'); if (!$this->packageManager->hasPackage($packageName)) { throw new RuntimeException(sprintf('The package "%s" is not installed.', $packageName)); } $this->packageManager->removePackage($packageName); return 0; }
/** * Handles the "config -r <key>" command. * * @param Args $args The console arguments. * * @return int The status code. */ public function handleReset(Args $args) { $this->manager->removeConfigKey($args->getArgument('key')); return 0; }
public function handleInstall(Args $args, IO $io) { if ($args->isArgumentSet('server')) { $expr = Expr::same($args->getArgument('server'), AssetMapping::SERVER_NAME); $mappings = $this->assetManager->findAssetMappings($expr); } else { $mappings = $this->assetManager->getAssetMappings(); } if (!$mappings) { $io->writeLine('Nothing to install.'); return 0; } /** @var InstallationParams[] $paramsToInstall */ $paramsToInstall = array(); // Prepare and validate the installation of all matching mappings foreach ($mappings as $mapping) { $paramsToInstall[] = $this->installationManager->prepareInstallation($mapping); } foreach ($paramsToInstall as $params) { foreach ($params->getResources() as $resource) { $serverPath = rtrim($params->getDocumentRoot(), '/') . $params->getServerPathForResource($resource); $io->writeLine(sprintf('Installing <c1>%s</c1> into <c2>%s</c2> via <u>%s</u>...', $resource->getRepositoryPath(), trim($serverPath, '/'), $params->getInstallerDescriptor()->getName())); $this->installationManager->installResource($resource, $params); } } return 0; }
public function handleSetDefault(Args $args) { $this->targetManager->setDefaultTarget($args->getArgument('name')); return 0; }
/** * Handles the "bind --disable" command. * * @param Args $args The console arguments. * * @return int The status code. */ public function handleDisable(Args $args) { $bindingToDisable = $this->getBindingByUuidPrefix($args->getArgument('uuid')); if ($bindingToDisable->getContainingPackage() instanceof RootPackage) { throw new RuntimeException(sprintf('Cannot disable bindings in the package "%s".', $bindingToDisable->getContainingPackage()->getName())); } $this->discoveryManager->disableBindingDescriptor($bindingToDisable->getUuid()); return 0; }
/** * Handles the "puli map --delete" command. * * @param Args $args The console arguments. * * @return int The status code. */ public function handleDelete(Args $args) { $repositoryPath = Path::makeAbsolute($args->getArgument('path'), $this->currentPath); if (!$this->repoManager->hasRootPathMapping($repositoryPath)) { throw new RuntimeException(sprintf('The path "%s" is not mapped in the package "%s".', $repositoryPath, $this->packages->getRootPackageName())); } $this->repoManager->removeRootPathMapping($repositoryPath); return 0; }