4
* Upload a chunk of text to the Paste application, or download one.
6
final class ArcanistPasteWorkflow extends ArcanistWorkflow {
13
public function getWorkflowName() {
17
public function getCommandSynopses() {
18
return phutil_console_format(<<<EOTEXT
19
**paste** [--title __title__] [--lang __language__] [--json]
20
**paste** __id__ [--json]
25
public function getCommandHelp() {
26
return phutil_console_format(<<<EOTEXT
28
Share and grab text using the Paste application. To create a paste,
29
use stdin to provide the text:
31
$ cat list_of_ducks.txt | arc paste
33
To retrieve a paste, specify the paste ID:
40
public function getArguments() {
44
'help' => 'Title for the paste.',
47
'param' => 'language',
48
'help' => 'Language for syntax highlighting.',
51
'help' => 'Output in JSON format.',
57
public function requiresAuthentication() {
61
protected function didParseArguments() {
62
$this->language = $this->getArgument('lang');
63
$this->title = $this->getArgument('title');
64
$this->json = $this->getArgument('json');
66
$argv = $this->getArgument('argv');
67
if (count($argv) > 1) {
68
throw new ArcanistUsageException('Specify only one paste to retrieve.');
69
} else if (count($argv) == 1) {
71
if (!preg_match('/^P?\d+/', $id)) {
72
throw new ArcanistUsageException('Specify a paste ID, like P123.');
74
$this->id = (int)ltrim($id, 'P');
76
if ($this->language || $this->title) {
77
throw new ArcanistUsageException(
78
'Use options --lang and --title only when creating pastes.');
83
private function getTitle() {
87
private function getLanguage() {
88
return $this->language;
91
private function getJSON() {
95
public function run() {
98
return $this->getPaste();
100
return $this->createPaste();
104
private function getPaste() {
105
$conduit = $this->getConduit();
107
$info = $conduit->callMethodSynchronous(
110
'ids' => array($this->id),
114
if ($this->getJSON()) {
115
echo json_encode($info)."\n";
117
echo $info['content'];
118
if (!preg_match('/\\n$/', $info['content'])) {
119
// If there's no newline, add one, since it looks stupid otherwise. If
120
// you want byte-for-byte equivalence you can use --json.
128
private function createPaste() {
129
$conduit = $this->getConduit();
131
// Avoid confusion when people type "arc paste" with nothing else.
132
$this->writeStatusMessage("Reading paste from stdin...\n");
134
$info = $conduit->callMethodSynchronous(
137
'content' => file_get_contents('php://stdin'),
138
'title' => $this->getTitle(),
139
'language' => $this->getLanguage(),
142
if ($this->getArgument('json')) {
143
echo json_encode($info)."\n";
145
echo $info['objectName'].': '.$info['uri']."\n";