mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
Add an "arc paste" workflow
Summary: Read and write in the same workflow! Dogs and cats living together! Test Plan: - Performed a bunch of paste reads and writes and they looked ok? Reviewed By: aran Reviewers: codeblock, jungejason, tuomaspelkonen, aran CC: aran Differential Revision: 748
This commit is contained in:
parent
42db1733b9
commit
0e4f7774fb
3 changed files with 176 additions and 0 deletions
|
@ -60,6 +60,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistNoLintLinter' => 'lint/linter/nolint',
|
'ArcanistNoLintLinter' => 'lint/linter/nolint',
|
||||||
'ArcanistNoLintTestCaseMisnamed' => 'lint/linter/nolint/__tests__',
|
'ArcanistNoLintTestCaseMisnamed' => 'lint/linter/nolint/__tests__',
|
||||||
'ArcanistPEP8Linter' => 'lint/linter/pep8',
|
'ArcanistPEP8Linter' => 'lint/linter/pep8',
|
||||||
|
'ArcanistPasteWorkflow' => 'workflow/paste',
|
||||||
'ArcanistPatchWorkflow' => 'workflow/patch',
|
'ArcanistPatchWorkflow' => 'workflow/patch',
|
||||||
'ArcanistPhutilModuleLinter' => 'lint/linter/phutilmodule',
|
'ArcanistPhutilModuleLinter' => 'lint/linter/phutilmodule',
|
||||||
'ArcanistPhutilTestCase' => 'unit/engine/phutil/testcase',
|
'ArcanistPhutilTestCase' => 'unit/engine/phutil/testcase',
|
||||||
|
@ -122,6 +123,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistNoLintLinter' => 'ArcanistLinter',
|
'ArcanistNoLintLinter' => 'ArcanistLinter',
|
||||||
'ArcanistNoLintTestCaseMisnamed' => 'ArcanistLinterTestCase',
|
'ArcanistNoLintTestCaseMisnamed' => 'ArcanistLinterTestCase',
|
||||||
'ArcanistPEP8Linter' => 'ArcanistLinter',
|
'ArcanistPEP8Linter' => 'ArcanistLinter',
|
||||||
|
'ArcanistPasteWorkflow' => 'ArcanistBaseWorkflow',
|
||||||
'ArcanistPatchWorkflow' => 'ArcanistBaseWorkflow',
|
'ArcanistPatchWorkflow' => 'ArcanistBaseWorkflow',
|
||||||
'ArcanistPhutilModuleLinter' => 'ArcanistLinter',
|
'ArcanistPhutilModuleLinter' => 'ArcanistLinter',
|
||||||
'ArcanistPyFlakesLinter' => 'ArcanistLinter',
|
'ArcanistPyFlakesLinter' => 'ArcanistLinter',
|
||||||
|
|
159
src/workflow/paste/ArcanistPasteWorkflow.php
Normal file
159
src/workflow/paste/ArcanistPasteWorkflow.php
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2011 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload a chunk of text to the Paste application, or download one.
|
||||||
|
*
|
||||||
|
* @group workflow
|
||||||
|
*/
|
||||||
|
final class ArcanistPasteWorkflow extends ArcanistBaseWorkflow {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
private $language;
|
||||||
|
private $title;
|
||||||
|
private $json;
|
||||||
|
|
||||||
|
public function getCommandHelp() {
|
||||||
|
return phutil_console_format(<<<EOTEXT
|
||||||
|
**paste** [--title __title__] [--lang __language__] [--json]
|
||||||
|
**paste** __id__ [--json]
|
||||||
|
Supports: text
|
||||||
|
Share and grab text using the Paste application. To create a paste,
|
||||||
|
use stdin to provide the text:
|
||||||
|
|
||||||
|
$ cat list_of_ducks.txt | arc paste
|
||||||
|
|
||||||
|
To retrieve a paste, specify the paste ID:
|
||||||
|
|
||||||
|
$ arc paste P123
|
||||||
|
|
||||||
|
EOTEXT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArguments() {
|
||||||
|
return array(
|
||||||
|
'title' => array(
|
||||||
|
'param' => 'title',
|
||||||
|
'help' => 'Title for the paste.',
|
||||||
|
),
|
||||||
|
'lang' => array(
|
||||||
|
'param' => 'language',
|
||||||
|
'help' => 'Language for syntax highlighting.',
|
||||||
|
),
|
||||||
|
'json' => array(
|
||||||
|
'help' => 'Output in JSON format.',
|
||||||
|
),
|
||||||
|
'*' => 'argv',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requiresAuthentication() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function didParseArguments() {
|
||||||
|
$this->language = $this->getArgument('lang');
|
||||||
|
$this->title = $this->getArgument('title');
|
||||||
|
$this->json = $this->getArgument('json');
|
||||||
|
|
||||||
|
$argv = $this->getArgument('argv');
|
||||||
|
if (count($argv) > 1) {
|
||||||
|
throw new ArcanistUsageException("Specify only one paste to retrieve.");
|
||||||
|
} else if (count($argv) == 1) {
|
||||||
|
$id = $argv[0];
|
||||||
|
if (!preg_match('/^P?\d+/', $id)) {
|
||||||
|
throw new ArcanistUsageException("Specify a paste ID, like P123.");
|
||||||
|
}
|
||||||
|
$this->id = (int)ltrim($id, 'P');
|
||||||
|
|
||||||
|
if ($this->language || $this->title) {
|
||||||
|
throw new ArcanistUsageException(
|
||||||
|
"Use options --lang and --title only when creating pastes.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTitle() {
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getLanguage() {
|
||||||
|
return $this->language;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getJSON() {
|
||||||
|
return $this->json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run() {
|
||||||
|
|
||||||
|
if ($this->id) {
|
||||||
|
return $this->getPaste();
|
||||||
|
} else {
|
||||||
|
return $this->createPaste();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getPaste() {
|
||||||
|
$conduit = $this->getConduit();
|
||||||
|
|
||||||
|
$info = $conduit->callMethodSynchronous(
|
||||||
|
'paste.info',
|
||||||
|
array(
|
||||||
|
'paste_id' => $this->id,
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($this->getJSON()) {
|
||||||
|
echo json_encode($info)."\n";
|
||||||
|
} else {
|
||||||
|
echo $info['content'];
|
||||||
|
if (!preg_match('/\\n$/', $info['content'])) {
|
||||||
|
// If there's no newline, add one, since it looks stupid otherwise. If
|
||||||
|
// you want byte-for-byte equivalence you can use --json.
|
||||||
|
echo "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createPaste() {
|
||||||
|
$conduit = $this->getConduit();
|
||||||
|
|
||||||
|
// Avoid confusion when people type "arc paste" with nothing else.
|
||||||
|
file_put_contents('php://stderr', "Reading paste from stdin...\n");
|
||||||
|
|
||||||
|
$info = $conduit->callMethodSynchronous(
|
||||||
|
'paste.create',
|
||||||
|
array(
|
||||||
|
'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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
src/workflow/paste/__init__.php
Normal file
15
src/workflow/paste/__init__.php
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is automatically generated. Lint this module to rebuild it.
|
||||||
|
* @generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_module('arcanist', 'exception/usage');
|
||||||
|
phutil_require_module('arcanist', 'workflow/base');
|
||||||
|
|
||||||
|
phutil_require_module('phutil', 'console');
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_source('ArcanistPasteWorkflow.php');
|
Loading…
Reference in a new issue