Page MenuHomePhabricator

D10099.diff
No OneTemporary

D10099.diff

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(<<<EOTEXT
**paste** [--title __title__] [--lang __language__] [--json]
**paste** __id__ [--json]
+ **paste** __id__ --edit [--title __title__] [--lang __language__] [--json]
EOTEXT
);
}
@@ -33,6 +35,10 @@
To retrieve a paste, specify the paste ID:
$ arc paste P123
+
+ To edit a paste, specify the paste ID and --edit option:
+
+ $ cat list_of_ducks.txt | arc paste P123 --edit
EOTEXT
);
}
@@ -50,6 +56,9 @@
'json' => 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;
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Thu, May 9, 8:55 PM (3 w, 1 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6277348
Default Alt Text
D10099.diff (2 KB)

Event Timeline