mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 05:42:40 +01:00
Minor tidying of lipsum generate
workflow
Summary: Just modernizing this a bit. Test Plan: Ran `./bin/lipsum generate`. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11907
This commit is contained in:
parent
644b05ec08
commit
ea337abafb
1 changed files with 38 additions and 22 deletions
|
@ -7,7 +7,7 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
$this
|
||||
->setName('generate')
|
||||
->setExamples('**generate**')
|
||||
->setSynopsis('Generate some lipsum.')
|
||||
->setSynopsis(pht('Generate some lipsum.'))
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
|
@ -18,21 +18,24 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
$supported_types = id(new PhutilSymbolLoader())
|
||||
->setAncestorClass('PhabricatorTestDataGenerator')
|
||||
->loadObjects();
|
||||
echo "These are the types of data you can generate:\n";
|
||||
foreach (array_keys($supported_types) as $typetmp) {
|
||||
echo "\t".$typetmp."\n";
|
||||
}
|
||||
echo "\n";
|
||||
$prompt = 'Are you sure you want to generate lots of test data?';
|
||||
if (!phutil_console_confirm($prompt, $default_no = true)) {
|
||||
|
||||
$console->writeOut(
|
||||
"%s:\n\t%s\n",
|
||||
pht('These are the types of data you can generate'),
|
||||
implode("\n\t", array_keys($supported_types)));
|
||||
|
||||
$prompt = pht('Are you sure you want to generate lots of test data?');
|
||||
if (!phutil_console_confirm($prompt, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$argv = $args->getArg('args');
|
||||
if (count($argv) == 0 ||
|
||||
(count($argv) == 1 && $argv[0] == 'all')) {
|
||||
if (count($argv) == 0 || (count($argv) == 1 && $argv[0] == 'all')) {
|
||||
$this->infinitelyGenerate($supported_types);
|
||||
} else {
|
||||
$new_supported_types = array();
|
||||
|
@ -41,24 +44,34 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
if (array_key_exists($arg, $supported_types)) {
|
||||
$new_supported_types[$arg] = $supported_types[$arg];
|
||||
} else {
|
||||
echo "The type ".$arg." is not supported by the lipsum generator.\n";
|
||||
$console->writeErr(
|
||||
"%s\n",
|
||||
pht(
|
||||
'The type %s is not supported by the lipsum generator.',
|
||||
$arg));
|
||||
}
|
||||
}
|
||||
$this->infinitelyGenerate($new_supported_types);
|
||||
}
|
||||
echo "None of the input types were supported.\n";
|
||||
echo "The supported types are:\n";
|
||||
echo implode("\n", array_keys($supported_types));
|
||||
|
||||
$console->writeOut(
|
||||
"%s\n%s:\n%s\n",
|
||||
pht('None of the input types were supported.'),
|
||||
pht('The supported types are'),
|
||||
implode("\n", array_keys($supported_types)));
|
||||
}
|
||||
|
||||
protected function infinitelyGenerate(array $supported_types) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
if (count($supported_types) == 0) {
|
||||
echo "None of the input types were supported.\n";
|
||||
return;
|
||||
}
|
||||
echo 'GENERATING: ';
|
||||
echo strtoupper(implode(' , ', array_keys($supported_types)));
|
||||
echo "\n";
|
||||
$console->writeOut(
|
||||
"%s: %s\n",
|
||||
pht('GENERATING'),
|
||||
implode(', ', array_keys($supported_types)));
|
||||
|
||||
while (true) {
|
||||
$type = $supported_types[array_rand($supported_types)];
|
||||
$admin = $this->getViewer();
|
||||
|
@ -69,8 +82,11 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
->setViewer($admin)
|
||||
->withPHIDs(array($object->getPHID()))
|
||||
->executeOne();
|
||||
echo "Generated ".$handle->getTypeName().": ".
|
||||
$handle->getFullName()."\n";
|
||||
|
||||
$console->writeOut(
|
||||
"%s: %s\n",
|
||||
pht('Generated %s', $handle->getTypeName()),
|
||||
$handle->getFullName());
|
||||
|
||||
usleep(200000);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue