diff --git a/src/workflow/ArcanistPasteWorkflow.php b/src/workflow/ArcanistPasteWorkflow.php --- a/src/workflow/ArcanistPasteWorkflow.php +++ b/src/workflow/ArcanistPasteWorkflow.php @@ -9,6 +9,7 @@ private $language; private $title; private $json; + private $edit; public function getWorkflowName() { return 'paste'; @@ -18,6 +19,7 @@ return phutil_console_format(<< array( 'help' => 'Output in JSON format.', ), + 'edit' => array( + 'help' => 'Edit an existing paste.', + ), '*' => 'argv', ); } @@ -62,6 +71,7 @@ $this->language = $this->getArgument('lang'); $this->title = $this->getArgument('title'); $this->json = $this->getArgument('json'); + $this->edit = $this->getArgument('edit'); $argv = $this->getArgument('argv'); if (count($argv) > 1) { @@ -73,11 +83,16 @@ } $this->id = (int)ltrim($id, 'P'); - if ($this->language || $this->title) { + if (!$this->getEdit() && ($this->language || $this->title)) { throw new ArcanistUsageException( - 'Use options --lang and --title only when creating pastes.'); + 'Use options --lang and --title only when creating or editing '. + 'pastes.'); } } + + if ($this->getEdit() && !$this->id) { + throw new ArcanistUsageException('Specify a paste to edit.'); + } } private function getTitle() { @@ -92,9 +107,15 @@ return $this->json; } + private function getEdit() { + return $this->edit; + } + public function run() { - if ($this->id) { + if ($this->getEdit()) { + return $this->editPaste(); + } else if ($this->id) { return $this->getPaste(); } else { return $this->createPaste(); @@ -148,4 +169,28 @@ return 0; } + private function editPaste() { + $conduit = $this->getConduit(); + + // Avoid confusion when people type "arc paste" with nothing else. + $this->writeStatusMessage("Reading paste from stdin...\n"); + + $info = $conduit->callMethodSynchronous( + 'paste.edit', + array( + 'paste_id' => $this->id, + 'content' => file_get_contents('php://stdin'), + 'title' => $this->getTitle(), + 'language' => $this->getLanguage(), + )); + + if ($this->getArgument('json')) { + echo json_encode($info)."\n"; + } else { + echo $info['objectName'].': '.$info['uri']."\n"; + } + + return 0; + } + }