diff --git a/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php b/src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php index 70f79309fd..2fe7c141f9 100644 --- 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 index c1daa0dea4..11e0baa6ec 100644 --- 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 index fe784dcb10..731bb0ccac 100644 --- a/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php +++ b/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php @@ -16,6 +16,10 @@ abstract class PhabricatorTestDataGenerator extends Phobject { 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 index 866e8b1cb0..46ea9b6bae 100644 --- a/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php +++ b/src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php @@ -30,14 +30,30 @@ final class PhabricatorLipsumGenerateWorkflow $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 @@ final class PhabricatorLipsumGenerateWorkflow 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 ($arg == $all) { - $generators[] = $generator; - $match = true; - break; + // 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 (strpos($name, $arg) !== false) { - $generators[] = $generator; - $match = true; - break; + if (!$matches) { + throw new PhutilArgumentUsageException( + pht( + 'Argument "%s" does not match the name of any generators.', + $arg_original)); + } + + 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( "** %s ** %s\n", pht('GENERATORS'), diff --git a/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php b/src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php index 50a1df77c0..404a36af8f 100644 --- 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 index 43be2d0eba..24ac718606 100644 --- 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 index 9b05b4acb1..7fe5065a42 100644 --- 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 index 9a274443cf..f81eb3e1d7 100644 --- 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 index 0b2e8e2943..0fd5bd66e7 100644 --- 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'); }