Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14009341
D10099.id24286.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10099.id24286.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 31, 2:38 PM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6731569
Default Alt Text
D10099.id24286.diff (2 KB)
Attached To
Mode
D10099: Adding support for editing paste in `arc paste` workflow
Attached
Detach File
Event Timeline
Log In to Comment