private function validate(Getopt $getopt) { if (!$getopt->hasErrors()) { return; } foreach ($getopt->getErrors() as $error) { $this->stdio->exception($error); } $this->showHelp(); exit(Status::USAGE); }
public function __construct(array $globals = null) { $this->version = new VersionInfo('writeme', '0.1.0', '<<green>>%s<<reset>> <<yellow>>%s<<reset>>'); $clif = new CliFactory(); if ($globals === null) { $globals = $GLOBALS; } $this->context = $clif->newContext($globals); $this->stdio = Stdio::create(); $this->placeholders = new PlaceholderCollection([new Frontmatter(), new TOC(), new API(), new Changelog(), new Badge()]); $placeholderDocs = new PlaceholderDocs(); $placeholderDocs->setPlaceholderCollection($this->placeholders); $this->placeholders->add($placeholderDocs); $this->converter = new Converter(); }
private function askForCustomOptionArray($currentValue, Option $option) { $da = new DotArray($currentValue); $this->stdio->outln($option->getPath()); $this->stdio->outln($option->getDescription()); $continue = true; while ($continue) { $this->stdio->displayList($da->flatten()); $actions = ['delete', 'clear all', 'add', 'replace', 'skip']; $action = $this->stdio->chooseAction($actions); switch ($action) { case 'delete': $index = $this->stdio->chooseFromList($da->flatten(), 'Item to delete', false); if ($index !== null) { $da->remove($index); } break; case 'clear all': $da = new DotArray(); break; case 'add': $newValue = $this->stdio->ask('Enter value of the new item'); $da = new DotArray(array_merge($da->getArray(), [$newValue])); break; case 'replace': $index = $this->stdio->chooseFromList($da->flatten(), 'Item to replace', false); if ($index !== null) { $da->set($index, $this->stdio->ask('Enter new value')); } break; case 'skip': $continue = false; break; } } $this->frontmatter->set($option->getPath(), $da->getArray()); }