Page MenuHomePhabricator

D17420.id41889.diff
No OneTemporary

D17420.id41889.diff

diff --git a/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php b/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
--- a/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
+++ b/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
@@ -3,6 +3,8 @@
final class PhabricatorDifferentialRevisionTestDataGenerator
extends PhabricatorTestDataGenerator {
+ const GENERATORKEY = 'revisions';
+
public function getGeneratorName() {
return pht('Differential Revisions');
}
diff --git a/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php b/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
--- a/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
+++ b/src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
@@ -3,6 +3,8 @@
final class PhabricatorFileTestDataGenerator
extends PhabricatorTestDataGenerator {
+ const GENERATORKEY = 'files';
+
public function getGeneratorName() {
return pht('Files');
}
diff --git a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
--- a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
+++ b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
@@ -16,6 +16,10 @@
return $this->viewer;
}
+ final public function getGeneratorKey() {
+ return $this->getPhobjectClassConstant('GENERATORKEY', 64);
+ }
+
protected function loadRandomPHID($table) {
$conn_r = $table->establishConnection('r');
diff --git a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
--- a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
+++ b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
@@ -30,14 +30,30 @@
$all_generators = id(new PhutilClassMapQuery())
->setAncestorClass('PhabricatorTestDataGenerator')
+ ->setUniqueMethod('getGeneratorKey')
->execute();
$argv = $args->getArg('args');
$all = 'all';
+ if (isset($all_generators[$all])) {
+ throw new Exception(
+ pht(
+ 'A lipsum generator is registered with key "%s". This key is '.
+ 'reserved.',
+ $all));
+ }
+
if (!$argv) {
- $names = mpull($all_generators, 'getGeneratorName');
- sort($names);
+ ksort($all_generators);
+
+ $names = array();
+ foreach ($all_generators as $generator) {
+ $names[] = tsprintf(
+ '%s (%s)',
+ $generator->getGeneratorKey(),
+ $generator->getGeneratorName());
+ }
$list = id(new PhutilConsoleList())
->setWrap(false)
@@ -59,31 +75,49 @@
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') {
+ $matches = $all_generators;
+ } else {
+ $matches = array();
+ foreach ($all_generators as $generator) {
+ $name = phutil_utf8_strtolower($generator->getGeneratorKey());
+
+ // If there's an exact match, select just that generator.
+ if ($arg == $name) {
+ $matches = array($generator);
+ break;
+ }
+
+ // If there's a partial match, match that generator but continue.
+ if (strpos($name, $arg) !== false) {
+ $matches[] = $generator;
+ }
+ }
- if ($arg == $all) {
- $generators[] = $generator;
- $match = true;
- break;
+ if (!$matches) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Argument "%s" does not match the name of any generators.',
+ $arg_original));
}
- if (strpos($name, $arg) !== false) {
- $generators[] = $generator;
- $match = true;
- break;
+ if (count($matches) > 1) {
+ throw new PhutilArgumentUsageException(
+ pht(
+ 'Argument "%s" is ambiguous, and matches multiple '.
+ 'generators: %s.',
+ $arg_original,
+ implode(', ', mpull($matches, 'getGeneratorName'))));
}
}
- if (!$match) {
- throw new PhutilArgumentUsageException(
- pht(
- 'Argument "%s" does not match the name of any generators.',
- $arg_original));
+ foreach ($matches as $match) {
+ $generators[] = $match;
}
}
+ $generators = mpull($generators, null, 'getGeneratorKey');
+
echo tsprintf(
"**<bg:blue> %s </bg>** %s\n",
pht('GENERATORS'),
diff --git a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
--- a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
+++ b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
@@ -3,6 +3,8 @@
final class PhabricatorManiphestTaskTestDataGenerator
extends PhabricatorTestDataGenerator {
+ const GENERATORKEY = 'tasks';
+
public function getGeneratorName() {
return pht('Maniphest Tasks');
}
diff --git a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
--- a/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
+++ b/src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
@@ -3,6 +3,8 @@
final class PhabricatorPasteTestDataGenerator
extends PhabricatorTestDataGenerator {
+ const GENERATORKEY = 'pastes';
+
public function getGeneratorName() {
return pht('Pastes');
}
diff --git a/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php b/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
--- a/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
+++ b/src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
@@ -3,6 +3,8 @@
final class PhabricatorPeopleTestDataGenerator
extends PhabricatorTestDataGenerator {
+ const GENERATORKEY = 'users';
+
public function getGeneratorName() {
return pht('User Accounts');
}
diff --git a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
--- a/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
+++ b/src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
@@ -3,6 +3,8 @@
final class PhabricatorPholioMockTestDataGenerator
extends PhabricatorTestDataGenerator {
+ const GENERATORKEY = 'mocks';
+
public function getGeneratorName() {
return pht('Pholio Mocks');
}
diff --git a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
--- a/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
+++ b/src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
@@ -3,6 +3,8 @@
final class PhabricatorProjectTestDataGenerator
extends PhabricatorTestDataGenerator {
+ const GENERATORKEY = 'projects';
+
public function getGeneratorName() {
return pht('Projects');
}

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 6, 9:46 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7225404
Default Alt Text
D17420.id41889.diff (7 KB)

Event Timeline