Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistFlagWorkflow.php
| Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
| EOTEXT | EOTEXT | ||||
| ); | ); | ||||
| } | } | ||||
| public function getArguments() { | public function getArguments() { | ||||
| return array( | return array( | ||||
| '*' => 'objects', | '*' => 'objects', | ||||
| 'clear' => array( | 'clear' => array( | ||||
| 'help' => 'Delete the flag on an object.', | 'help' => pht('Delete the flag on an object.'), | ||||
| ), | ), | ||||
| 'edit' => array( | 'edit' => array( | ||||
| 'help' => 'Edit the flag on an object.', | 'help' => pht('Edit the flag on an object.'), | ||||
| ), | ), | ||||
| 'color' => array( | 'color' => array( | ||||
| 'param' => 'color', | 'param' => 'color', | ||||
| 'help' => 'Set the color of a flag.', | 'help' => pht('Set the color of a flag.'), | ||||
| ), | ), | ||||
| 'note' => array( | 'note' => array( | ||||
| 'param' => 'note', | 'param' => 'note', | ||||
| 'help' => 'Set the note on a flag.', | 'help' => pht('Set the note on a flag.'), | ||||
| ), | ), | ||||
| ); | ); | ||||
| } | } | ||||
| public function requiresConduit() { | public function requiresConduit() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| Show All 29 Lines | public function run() { | ||||
| $clear = $this->getArgument('clear'); | $clear = $this->getArgument('clear'); | ||||
| $edit = $this->getArgument('edit'); | $edit = $this->getArgument('edit'); | ||||
| // I don't trust PHP to distinguish 0 (red) from null. | // I don't trust PHP to distinguish 0 (red) from null. | ||||
| $color = $this->getArgument('color', -1); | $color = $this->getArgument('color', -1); | ||||
| $note = $this->getArgument('note'); | $note = $this->getArgument('note'); | ||||
| $editing = $edit || ($color != -1) || $note; | $editing = $edit || ($color != -1) || $note; | ||||
| if ($editing && $clear) { | if ($editing && $clear) { | ||||
| throw new ArcanistUsageException("You can't both edit and clear a flag."); | throw new ArcanistUsageException( | ||||
| pht("You can't both edit and clear a flag.")); | |||||
| } | } | ||||
| if (($editing || $clear) && count($objects) != 1) { | if (($editing || $clear) && count($objects) != 1) { | ||||
| throw new ArcanistUsageException('Specify exactly one object.'); | throw new ArcanistUsageException(pht('Specify exactly one object.')); | ||||
| } | } | ||||
| if (!empty($objects)) { | if (!empty($objects)) { | ||||
| // First off, convert the passed objects to PHIDs. | // First off, convert the passed objects to PHIDs. | ||||
| $handles = $conduit->callMethodSynchronous( | $handles = $conduit->callMethodSynchronous( | ||||
| 'phid.lookup', | 'phid.lookup', | ||||
| array( | array( | ||||
| 'names' => $objects, | 'names' => $objects, | ||||
| )); | )); | ||||
| foreach ($objects as $object) { | foreach ($objects as $object) { | ||||
| if (isset($handles[$object])) { | if (isset($handles[$object])) { | ||||
| $phids[$object] = $handles[$object]['phid']; | $phids[$object] = $handles[$object]['phid']; | ||||
| } else { | } else { | ||||
| echo phutil_console_format("**%s** doesn't exist.\n", $object); | echo pht( | ||||
| "%s doesn't exist.\n", | |||||
| phutil_console_format('**%s**', $object)); | |||||
| } | } | ||||
| } | } | ||||
| if (empty($phids)) { | if (empty($phids)) { | ||||
| // flag.query treats an empty objectPHIDs parameter as "don't use this | // flag.query treats an empty objectPHIDs parameter as "don't use this | ||||
| // constraint". However, if the user gives a list of objects but none | // constraint". However, if the user gives a list of objects but none | ||||
| // of them exist and have flags, we shouldn't dump the full list on | // of them exist and have flags, we shouldn't dump the full list on | ||||
| // them after telling them that. Conveniently, we already told them, | // them after telling them that. Conveniently, we already told them, | ||||
| // so we can go quit now. | // so we can go quit now. | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||
| if ($clear) { | if ($clear) { | ||||
| // All right, we're going to clear a flag. First clear it. Then tell the | // All right, we're going to clear a flag. First clear it. Then tell the | ||||
| // user we cleared it. Step four: profit! | // user we cleared it. Step four: profit! | ||||
| $flag = $conduit->callMethodSynchronous( | $flag = $conduit->callMethodSynchronous( | ||||
| 'flag.delete', | 'flag.delete', | ||||
| array( | array( | ||||
| 'objectPHID' => head($phids), | 'objectPHID' => head($phids), | ||||
| )); | )); | ||||
| if (!$flag) { | if (!$flag) { | ||||
| echo phutil_console_format("**%s** has no flag to clear.\n", $object); | echo pht( | ||||
| "%s has no flag to clear.\n", | |||||
| phutil_console_format('**%s**', $object)); | |||||
| } else { | } else { | ||||
| self::flagWasEdited($flag, 'deleted'); | self::flagWasEdited($flag, 'deleted'); | ||||
| } | } | ||||
| } else if ($editing) { | } else if ($editing) { | ||||
| // Let's set some flags. Just like Minesweeper, but less distracting. | // Let's set some flags. Just like Minesweeper, but less distracting. | ||||
| $flag_params = array( | $flag_params = array( | ||||
| 'objectPHID' => head($phids), | 'objectPHID' => head($phids), | ||||
| ); | ); | ||||
| Show All 16 Lines | if ($clear) { | ||||
| array( | array( | ||||
| 'ownerPHIDs' => array($this->getUserPHID()), | 'ownerPHIDs' => array($this->getUserPHID()), | ||||
| 'objectPHIDs' => array_values($phids), | 'objectPHIDs' => array_values($phids), | ||||
| )), | )), | ||||
| null, | null, | ||||
| 'objectPHID'); | 'objectPHID'); | ||||
| foreach ($phids as $object => $phid) { | foreach ($phids as $object => $phid) { | ||||
| if (!isset($flags[$phid])) { | if (!isset($flags[$phid])) { | ||||
| echo phutil_console_format("**%s** has no flag.\n", $object); | echo pht( | ||||
| "%s has no flag.\n", | |||||
| phutil_console_format('**%s**', $object)); | |||||
| } | } | ||||
| } | } | ||||
| if (empty($flags)) { | if (empty($flags)) { | ||||
| // If the user passed no object names, then we should print the full | // If the user passed no object names, then we should print the full | ||||
| // list, but it's empty, so tell the user they have no flags. | // list, but it's empty, so tell the user they have no flags. | ||||
| // If the user passed object names, we already told them all their | // If the user passed object names, we already told them all their | ||||
| // objects are nonexistent or unflagged. | // objects are nonexistent or unflagged. | ||||
| if (empty($objects)) { | if (empty($objects)) { | ||||
| echo "You have no flagged objects.\n"; | echo pht('You have no flagged objects.')."\n"; | ||||
| } | } | ||||
| } else { | } else { | ||||
| // Print ALL the flags. With fancy formatting. Because fancy formatting | // Print ALL the flags. With fancy formatting. Because fancy formatting | ||||
| // is _cool_. | // is _cool_. | ||||
| $name_len = 1 + max(array_map('strlen', ipull($flags, 'colorName'))); | $name_len = 1 + max(array_map('strlen', ipull($flags, 'colorName'))); | ||||
| foreach ($flags as $flag) { | foreach ($flags as $flag) { | ||||
| $color = idx(self::$colorMap, $flag['color'], 'cyan'); | $color = idx(self::$colorMap, $flag['color'], 'cyan'); | ||||
| echo phutil_console_format( | echo phutil_console_format( | ||||
| Show All 13 Lines | |||||