mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 04:42:40 +01:00
Improve bin/lipsum UX
Summary: Ref T9156. This makes the UX a little more modern/standard/safe. Test Plan: ``` epriestley@orbital ~/dev/phabricator $ ./bin/lipsum generate Choose which type or types of test data you want to generate, or select "all". - Differential Revisions - Files - Maniphest Tasks - Pastes - Pholio Mocks - Projects - User Accounts ``` Reviewers: chad Reviewed By: chad Maniphest Tasks: T9156 Differential Revision: https://secure.phabricator.com/D14873
This commit is contained in:
parent
1c572d1da5
commit
ba37149bf9
10 changed files with 141 additions and 67 deletions
|
@ -5,10 +5,10 @@ $root = dirname(dirname(dirname(__FILE__)));
|
|||
require_once $root.'/scripts/__init_script__.php';
|
||||
|
||||
$args = new PhutilArgumentParser($argv);
|
||||
$args->setTagline(pht('manage lipsum'));
|
||||
$args->setTagline(pht('synthetic data generator'));
|
||||
$args->setSynopsis(<<<EOSYNOPSIS
|
||||
**lipsum** __command__ [__options__]
|
||||
Manage Phabricator Test Data Generator.
|
||||
Generate synthetic test data to make development easier.
|
||||
|
||||
EOSYNOPSIS
|
||||
);
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
final class PhabricatorDifferentialRevisionTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
public function generate() {
|
||||
public function getGeneratorName() {
|
||||
return pht('Differential Revisions');
|
||||
}
|
||||
|
||||
public function generateObject() {
|
||||
$author = $this->loadPhabrictorUser();
|
||||
|
||||
$revision = DifferentialRevision::initializeNewRevision($author);
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
final class PhabricatorFileTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
public function generate() {
|
||||
public function getGeneratorName() {
|
||||
return pht('Files');
|
||||
}
|
||||
|
||||
public function generateObject() {
|
||||
$author_phid = $this->loadPhabrictorUserPHID();
|
||||
$dimension = 1 << rand(5, 12);
|
||||
$image = id(new PhabricatorLipsumMondrianArtist())
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
abstract class PhabricatorTestDataGenerator extends Phobject {
|
||||
|
||||
public function generate() {
|
||||
return;
|
||||
}
|
||||
abstract public function getGeneratorName();
|
||||
abstract public function generateObject();
|
||||
|
||||
public function loadOneRandom($classname) {
|
||||
try {
|
||||
|
|
|
@ -7,7 +7,7 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
$this
|
||||
->setName('generate')
|
||||
->setExamples('**generate**')
|
||||
->setSynopsis(pht('Generate some lipsum.'))
|
||||
->setSynopsis(pht('Generate synthetic test objects.'))
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
|
@ -18,77 +18,124 @@ final class PhabricatorLipsumGenerateWorkflow
|
|||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
$config_key = 'phabricator.developer-mode';
|
||||
if (!PhabricatorEnv::getEnvConfig($config_key)) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht(
|
||||
'lipsum is a development and testing tool and may only be run '.
|
||||
'on installs in developer mode. Enable "%s" in your configuration '.
|
||||
'to enable lipsum.',
|
||||
$config_key));
|
||||
}
|
||||
|
||||
$supported_types = id(new PhutilClassMapQuery())
|
||||
$all_generators = id(new PhutilClassMapQuery())
|
||||
->setAncestorClass('PhabricatorTestDataGenerator')
|
||||
->execute();
|
||||
|
||||
$console->writeOut(
|
||||
"%s:\n\t%s\n",
|
||||
pht('These are the types of data you can generate'),
|
||||
implode("\n\t", array_keys($supported_types)));
|
||||
$argv = $args->getArg('args');
|
||||
$all = 'all';
|
||||
|
||||
$prompt = pht('Are you sure you want to generate lots of test data?');
|
||||
if (!$argv) {
|
||||
$names = mpull($all_generators, 'getGeneratorName');
|
||||
sort($names);
|
||||
|
||||
$list = id(new PhutilConsoleList())
|
||||
->setWrap(false)
|
||||
->addItems($names);
|
||||
|
||||
id(new PhutilConsoleBlock())
|
||||
->addParagraph(
|
||||
pht(
|
||||
'Choose which type or types of test data you want to generate, '.
|
||||
'or select "%s".',
|
||||
$all))
|
||||
->addList($list)
|
||||
->draw();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$generators = array();
|
||||
foreach ($argv as $arg_original) {
|
||||
$arg = phutil_utf8_strtolower($arg_original);
|
||||
|
||||
$match = false;
|
||||
foreach ($all_generators as $generator) {
|
||||
$name = phutil_utf8_strtolower($generator->getGeneratorName());
|
||||
|
||||
if ($arg == $all) {
|
||||
$generators[] = $generator;
|
||||
$match = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (strpos($name, $arg) !== false) {
|
||||
$generators[] = $generator;
|
||||
$match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$match) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht(
|
||||
'Argument "%s" does not match the name of any generators.',
|
||||
$arg_original));
|
||||
}
|
||||
}
|
||||
|
||||
echo tsprintf(
|
||||
"**<bg:blue> %s </bg>** %s\n",
|
||||
pht('GENERATORS'),
|
||||
pht(
|
||||
'Selected generators: %s.',
|
||||
implode(', ', mpull($generators, 'getGeneratorName'))));
|
||||
|
||||
echo tsprintf(
|
||||
"**<bg:yellow> %s </bg>** %s\n",
|
||||
pht('WARNING'),
|
||||
pht(
|
||||
'This command generates synthetic test data, including user '.
|
||||
'accounts. It is intended for use in development environments '.
|
||||
'so you can test features more easily. There is no easy way to '.
|
||||
'delete this data or undo the effects of this command. If you run '.
|
||||
'it in a production environment, it will pollute your data with '.
|
||||
'large amounts of meaningless garbage that you can not get rid of.'));
|
||||
|
||||
$prompt = pht('Are you sure you want to generate piles of garbage?');
|
||||
if (!phutil_console_confirm($prompt, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$argv = $args->getArg('args');
|
||||
if (count($argv) == 0 || (count($argv) == 1 && $argv[0] == 'all')) {
|
||||
$this->infinitelyGenerate($supported_types);
|
||||
} else {
|
||||
$new_supported_types = array();
|
||||
for ($i = 0; $i < count($argv); $i++) {
|
||||
$arg = $argv[$i];
|
||||
if (array_key_exists($arg, $supported_types)) {
|
||||
$new_supported_types[$arg] = $supported_types[$arg];
|
||||
} else {
|
||||
$console->writeErr(
|
||||
"%s\n",
|
||||
pht(
|
||||
'The type %s is not supported by the lipsum generator.',
|
||||
$arg));
|
||||
}
|
||||
}
|
||||
$this->infinitelyGenerate($new_supported_types);
|
||||
}
|
||||
echo tsprintf(
|
||||
"**<bg:green> %s </bg>** %s\n",
|
||||
pht('LIPSUM'),
|
||||
pht(
|
||||
'Generating synthetic test objects forever. '.
|
||||
'Use ^C to stop when satisfied.'));
|
||||
|
||||
$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)));
|
||||
$this->generate($generators);
|
||||
}
|
||||
|
||||
protected function infinitelyGenerate(array $supported_types) {
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
if (count($supported_types) == 0) {
|
||||
return;
|
||||
}
|
||||
$console->writeOut(
|
||||
"%s: %s\n",
|
||||
pht('GENERATING'),
|
||||
implode(', ', array_keys($supported_types)));
|
||||
protected function generate(array $generators) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
while (true) {
|
||||
$type = $supported_types[array_rand($supported_types)];
|
||||
$admin = $this->getViewer();
|
||||
$generator = $generators[array_rand($generators)];
|
||||
|
||||
$taskgen = newv($type, array());
|
||||
$object = $taskgen->generate();
|
||||
$handle = id(new PhabricatorHandleQuery())
|
||||
->setViewer($admin)
|
||||
->withPHIDs(array($object->getPHID()))
|
||||
->executeOne();
|
||||
$object = $generator->generateObject();
|
||||
$object_phid = $object->getPHID();
|
||||
|
||||
$console->writeOut(
|
||||
"%s: %s\n",
|
||||
pht('Generated %s', $handle->getTypeName()),
|
||||
$handle->getFullName());
|
||||
$handles = $viewer->loadHandles(array($object_phid));
|
||||
|
||||
usleep(200000);
|
||||
echo tsprintf(
|
||||
"%s\n",
|
||||
pht(
|
||||
'Generated "%s": %s',
|
||||
$handles[$object_phid]->getTypeName(),
|
||||
$handles[$object_phid]->getFullName()));
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
final class PhabricatorManiphestTaskTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
public function generate() {
|
||||
public function getGeneratorName() {
|
||||
return pht('Maniphest Tasks');
|
||||
}
|
||||
|
||||
public function generateObject() {
|
||||
$author_phid = $this->loadPhabrictorUserPHID();
|
||||
$author = id(new PhabricatorUser())
|
||||
->loadOneWhere('phid = %s', $author_phid);
|
||||
|
|
|
@ -3,13 +3,17 @@
|
|||
final class PhabricatorPasteTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
public function getGeneratorName() {
|
||||
return pht('Pastes');
|
||||
}
|
||||
|
||||
// Better Support for this in the future
|
||||
public $supportedLanguages = array(
|
||||
'Java' => 'java',
|
||||
'PHP' => 'php',
|
||||
);
|
||||
|
||||
public function generate() {
|
||||
public function generateObject() {
|
||||
$author = $this->loadPhabrictorUser();
|
||||
$authorphid = $author->getPHID();
|
||||
$language = $this->generateLanguage();
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
final class PhabricatorPeopleTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
public function generate() {
|
||||
public function getGeneratorName() {
|
||||
return pht('User Accounts');
|
||||
}
|
||||
|
||||
public function generateObject() {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
final class PhabricatorPholioMockTestDataGenerator
|
||||
extends PhabricatorTestDataGenerator {
|
||||
|
||||
public function generate() {
|
||||
public function getGeneratorName() {
|
||||
return pht('Pholio Mocks');
|
||||
}
|
||||
|
||||
public function generateObject() {
|
||||
$author_phid = $this->loadPhabrictorUserPHID();
|
||||
$author = id(new PhabricatorUser())
|
||||
->loadOneWhere('phid = %s', $author_phid);
|
||||
|
|
|
@ -5,7 +5,11 @@ final class PhabricatorProjectTestDataGenerator
|
|||
|
||||
private $xactions = array();
|
||||
|
||||
public function generate() {
|
||||
public function getGeneratorName() {
|
||||
return pht('Projects');
|
||||
}
|
||||
|
||||
public function generateObject() {
|
||||
$title = $this->generateTitle();
|
||||
$author = $this->loadPhabrictorUser();
|
||||
$author_phid = $author->getPHID();
|
||||
|
|
Loading…
Reference in a new issue