Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistPasteWorkflow.php
| <?php | <?php | ||||
| final class ArcanistPasteWorkflow | final class ArcanistPasteWorkflow | ||||
| extends ArcanistArcWorkflow { | extends ArcanistArcWorkflow { | ||||
| public function getWorkflowName() { | public function getWorkflowName() { | ||||
| return 'paste'; | return 'paste'; | ||||
| } | } | ||||
| public function getWorkflowInformation() { | public function getWorkflowInformation() { | ||||
| $help = pht(<<<EOTEXT | $help = pht(<<<EOTEXT | ||||
| Share and grab text using the Paste application. To create a paste, | Share and grab text using the Paste application. To create a paste, use the | ||||
| use stdin to provide the text: | "--input" flag or provide the text on stdin: | ||||
| $ cat list_of_ducks.txt | arc paste | $ cat list_of_ducks.txt | arc paste | ||||
| $ arc paste --input list_of_ducks.txt | |||||
| To retrieve a paste, specify the paste ID: | To retrieve a paste, specify the paste ID: | ||||
| $ arc paste P123 | $ arc paste P123 | ||||
| EOTEXT | EOTEXT | ||||
| ); | ); | ||||
| return $this->newWorkflowInformation() | return $this->newWorkflowInformation() | ||||
| ->addExample('**paste** [__options__] --') | ->addExample('**paste** [__options__] --') | ||||
| ->addExample('**paste** [__options__] -- __object__') | ->addExample('**paste** [__options__] -- __object__') | ||||
| ->setHelp($help); | ->setHelp($help); | ||||
| } | } | ||||
| public function getWorkflowArguments() { | public function getWorkflowArguments() { | ||||
| return array( | return array( | ||||
| $this->newWorkflowArgument('title') | $this->newWorkflowArgument('title') | ||||
| ->setParameter('title') | ->setParameter('title') | ||||
| ->setHelp(pht('Title for the paste.')), | ->setHelp(pht('Title for the paste.')), | ||||
| $this->newWorkflowArgument('lang') | $this->newWorkflowArgument('lang') | ||||
| ->setParameter('language') | ->setParameter('language') | ||||
| ->setHelp(pht('Language for the paste.')), | ->setHelp(pht('Language for the paste.')), | ||||
| $this->newWorkflowArgument('json') | $this->newWorkflowArgument('input') | ||||
| ->setHelp(pht('Output in JSON format.')), | ->setParameter('path') | ||||
| ->setIsPathArgument(true) | |||||
| ->setHelp(pht('Create a paste using the content in a file.')), | |||||
| $this->newWorkflowArgument('browse') | |||||
| ->setHelp(pht('After creating a paste, open it in a web browser.')), | |||||
| $this->newWorkflowArgument('argv') | $this->newWorkflowArgument('argv') | ||||
| ->setWildcard(true), | ->setWildcard(true), | ||||
| ); | ); | ||||
| } | } | ||||
| public function runWorkflow() { | public function runWorkflow() { | ||||
| $set_language = $this->getArgument('lang'); | $set_language = $this->getArgument('lang'); | ||||
| $set_title = $this->getArgument('title'); | $set_title = $this->getArgument('title'); | ||||
| $is_browse = $this->getArgument('browse'); | |||||
| $input_path = $this->getArgument('input'); | |||||
| $argv = $this->getArgument('argv'); | $argv = $this->getArgument('argv'); | ||||
| if (count($argv) > 1) { | if (count($argv) > 1) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'Specify only one paste to retrieve.')); | 'Specify only one paste to retrieve.')); | ||||
| } | } | ||||
| $is_read = (count($argv) === 1); | |||||
| $symbols = $this->getSymbolEngine(); | $symbols = $this->getSymbolEngine(); | ||||
| if (count($argv) === 1) { | if (count($argv) === 1) { | ||||
| if ($set_language !== null) { | if ($set_language !== null) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'Flag "--lang" is not supported when reading pastes.')); | 'Flag "--lang" is not supported when reading pastes.')); | ||||
| } | } | ||||
| if ($set_title !== null) { | if ($set_title !== null) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'Flag "--title" is not supported when reading pastes.')); | 'Flag "--title" is not supported when reading pastes.')); | ||||
| } | } | ||||
| if ($is_browse) { | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht( | |||||
| 'Flag "--browse" is not supported when reading pastes. Use '. | |||||
| '"arc browse" to browse known objects.')); | |||||
| } | |||||
| if ($input_path !== null) { | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht( | |||||
| 'Flag "--input" is not supported when reading pastes.')); | |||||
| } | |||||
| $paste_symbol = $argv[0]; | $paste_symbol = $argv[0]; | ||||
| $paste_ref = $symbols->loadPasteForSymbol($paste_symbol); | $paste_ref = $symbols->loadPasteForSymbol($paste_symbol); | ||||
| if (!$paste_ref) { | if (!$paste_ref) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'Paste "%s" does not exist, or you do not have access '. | 'Paste "%s" does not exist, or you do not have access '. | ||||
| 'to see it.')); | 'to see it.', | ||||
| $paste_symbol)); | |||||
| } | } | ||||
| echo $paste_ref->getContent(); | echo $paste_ref->getContent(); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| if ($input_path === null || $input_path === '-') { | |||||
| $content = $this->readStdin(); | $content = $this->readStdin(); | ||||
| } else { | |||||
| $content = Filesystem::readFile($input_path); | |||||
| } | |||||
| $xactions = array(); | $xactions = array(); | ||||
| if ($set_title === null) { | if ($set_title === null) { | ||||
| $set_title = pht('Command-Line Input'); | $set_title = pht('Command-Line Input'); | ||||
| } | } | ||||
| $xactions[] = array( | $xactions[] = array( | ||||
| Show All 22 Lines | public function runWorkflow() { | ||||
| $conduit_engine = $this->getConduitEngine(); | $conduit_engine = $this->getConduitEngine(); | ||||
| $conduit_call = $conduit_engine->newCall($method, $parameters); | $conduit_call = $conduit_engine->newCall($method, $parameters); | ||||
| $conduit_future = $conduit_engine->newFuture($conduit_call); | $conduit_future = $conduit_engine->newFuture($conduit_call); | ||||
| $result = $conduit_future->resolve(); | $result = $conduit_future->resolve(); | ||||
| $paste_phid = idxv($result, array('object', 'phid')); | $paste_phid = idxv($result, array('object', 'phid')); | ||||
| $paste_ref = $symbols->loadPasteForSymbol($paste_phid); | $paste_ref = $symbols->loadPasteForSymbol($paste_phid); | ||||
| $uri = $paste_ref->getURI(); | |||||
| $uri = $this->getAbsoluteURI($uri); | |||||
| $log = $this->getLogEngine(); | $log = $this->getLogEngine(); | ||||
| $log->writeSuccess( | $log->writeSuccess( | ||||
| pht('DONE'), | pht('DONE'), | ||||
| pht('Created a new paste.')); | pht('Created a new paste.')); | ||||
| echo tsprintf( | echo tsprintf( | ||||
| '%s', | '%s', | ||||
| $paste_ref->newDisplayRef() | $paste_ref->newDisplayRef() | ||||
| ->setURI($paste_ref->getURI())); | ->setURI($uri)); | ||||
| if ($is_browse) { | |||||
| $this->openURIsInBrowser(array($uri)); | |||||
| } | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| } | } | ||||