@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make `bin/lipsum generate` hanldle generator keys and arguments more clearly

Summary:
Ref T12319. Currently, `bin/lipsum` uses substring matches against human-readable text to chose which objects to generate.

Instead:

- Use separate selector keys which are guaranteed to be unique.
- When a match is exact, select only that generator.
- When a match is ambiguous, fail and warn the user.

Test Plan: Generated several types of objects, tried to generate ambiguous objects like "e".

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12319

Differential Revision: https://secure.phabricator.com/D17420

+70 -18
+2
src/applications/differential/lipsum/PhabricatorDifferentialRevisionTestDataGenerator.php
··· 3 3 final class PhabricatorDifferentialRevisionTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 + const GENERATORKEY = 'revisions'; 7 + 6 8 public function getGeneratorName() { 7 9 return pht('Differential Revisions'); 8 10 }
+2
src/applications/files/lipsum/PhabricatorFileTestDataGenerator.php
··· 3 3 final class PhabricatorFileTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 + const GENERATORKEY = 'files'; 7 + 6 8 public function getGeneratorName() { 7 9 return pht('Files'); 8 10 }
+4
src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
··· 16 16 return $this->viewer; 17 17 } 18 18 19 + final public function getGeneratorKey() { 20 + return $this->getPhobjectClassConstant('GENERATORKEY', 64); 21 + } 22 + 19 23 protected function loadRandomPHID($table) { 20 24 $conn_r = $table->establishConnection('r'); 21 25
+52 -18
src/applications/lipsum/management/PhabricatorLipsumGenerateWorkflow.php
··· 30 30 31 31 $all_generators = id(new PhutilClassMapQuery()) 32 32 ->setAncestorClass('PhabricatorTestDataGenerator') 33 + ->setUniqueMethod('getGeneratorKey') 33 34 ->execute(); 34 35 35 36 $argv = $args->getArg('args'); 36 37 $all = 'all'; 38 + 39 + if (isset($all_generators[$all])) { 40 + throw new Exception( 41 + pht( 42 + 'A lipsum generator is registered with key "%s". This key is '. 43 + 'reserved.', 44 + $all)); 45 + } 37 46 38 47 if (!$argv) { 39 - $names = mpull($all_generators, 'getGeneratorName'); 40 - sort($names); 48 + ksort($all_generators); 49 + 50 + $names = array(); 51 + foreach ($all_generators as $generator) { 52 + $names[] = tsprintf( 53 + '%s (%s)', 54 + $generator->getGeneratorKey(), 55 + $generator->getGeneratorName()); 56 + } 41 57 42 58 $list = id(new PhutilConsoleList()) 43 59 ->setWrap(false) ··· 59 75 foreach ($argv as $arg_original) { 60 76 $arg = phutil_utf8_strtolower($arg_original); 61 77 62 - $match = false; 63 - foreach ($all_generators as $generator) { 64 - $name = phutil_utf8_strtolower($generator->getGeneratorName()); 78 + if ($arg == 'all') { 79 + $matches = $all_generators; 80 + } else { 81 + $matches = array(); 82 + foreach ($all_generators as $generator) { 83 + $name = phutil_utf8_strtolower($generator->getGeneratorKey()); 65 84 66 - if ($arg == $all) { 67 - $generators[] = $generator; 68 - $match = true; 69 - break; 85 + // If there's an exact match, select just that generator. 86 + if ($arg == $name) { 87 + $matches = array($generator); 88 + break; 89 + } 90 + 91 + // If there's a partial match, match that generator but continue. 92 + if (strpos($name, $arg) !== false) { 93 + $matches[] = $generator; 94 + } 70 95 } 71 96 72 - if (strpos($name, $arg) !== false) { 73 - $generators[] = $generator; 74 - $match = true; 75 - break; 97 + if (!$matches) { 98 + throw new PhutilArgumentUsageException( 99 + pht( 100 + 'Argument "%s" does not match the name of any generators.', 101 + $arg_original)); 102 + } 103 + 104 + if (count($matches) > 1) { 105 + throw new PhutilArgumentUsageException( 106 + pht( 107 + 'Argument "%s" is ambiguous, and matches multiple '. 108 + 'generators: %s.', 109 + $arg_original, 110 + implode(', ', mpull($matches, 'getGeneratorName')))); 76 111 } 77 112 } 78 113 79 - if (!$match) { 80 - throw new PhutilArgumentUsageException( 81 - pht( 82 - 'Argument "%s" does not match the name of any generators.', 83 - $arg_original)); 114 + foreach ($matches as $match) { 115 + $generators[] = $match; 84 116 } 85 117 } 118 + 119 + $generators = mpull($generators, null, 'getGeneratorKey'); 86 120 87 121 echo tsprintf( 88 122 "**<bg:blue> %s </bg>** %s\n",
+2
src/applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php
··· 3 3 final class PhabricatorManiphestTaskTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 + const GENERATORKEY = 'tasks'; 7 + 6 8 public function getGeneratorName() { 7 9 return pht('Maniphest Tasks'); 8 10 }
+2
src/applications/paste/lipsum/PhabricatorPasteTestDataGenerator.php
··· 3 3 final class PhabricatorPasteTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 + const GENERATORKEY = 'pastes'; 7 + 6 8 public function getGeneratorName() { 7 9 return pht('Pastes'); 8 10 }
+2
src/applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php
··· 3 3 final class PhabricatorPeopleTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 + const GENERATORKEY = 'users'; 7 + 6 8 public function getGeneratorName() { 7 9 return pht('User Accounts'); 8 10 }
+2
src/applications/pholio/lipsum/PhabricatorPholioMockTestDataGenerator.php
··· 3 3 final class PhabricatorPholioMockTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 + const GENERATORKEY = 'mocks'; 7 + 6 8 public function getGeneratorName() { 7 9 return pht('Pholio Mocks'); 8 10 }
+2
src/applications/project/lipsum/PhabricatorProjectTestDataGenerator.php
··· 3 3 final class PhabricatorProjectTestDataGenerator 4 4 extends PhabricatorTestDataGenerator { 5 5 6 + const GENERATORKEY = 'projects'; 7 + 6 8 public function getGeneratorName() { 7 9 return pht('Projects'); 8 10 }