1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 08:12:40 +01:00

Add "--browse" and "--input" to "arc paste", and remove "--json" (which had no effect)

Summary:
Ref T13528. For consistency with other commands ("arc upload", "arc diff"), support a "--browse" flag to "arc paste".

Support "--input" as a more robust alternative to `x | y` (see T6996).

Test Plan: Ran `arc paste --browse --input X`, got a new paste in a browser window. Ran other variations of flags and parameters.

Maniphest Tasks: T13528

Differential Revision: https://secure.phabricator.com/D21203
This commit is contained in:
epriestley 2020-05-01 08:49:26 -07:00
parent c0d151e0e9
commit af9faba02f
2 changed files with 48 additions and 8 deletions

View file

@ -30,7 +30,13 @@ final class ArcanistPasteRef
} }
public function getURI() { public function getURI() {
return idxv($this->parameters, array('fields', 'uri')); $uri = idxv($this->parameters, array('fields', 'uri'));
if ($uri === null) {
$uri = '/'.$this->getMonogram();
}
return $uri;
} }
public function getContent() { public function getContent() {

View file

@ -9,10 +9,11 @@ final class ArcanistPasteWorkflow
public function getWorkflowInformation() { public function getWorkflowInformation() {
$help = pht(<<<EOTEXT $help = pht(<<<EOTEXT
Share and grab text using the Paste application. To create a paste, Share and grab text using the Paste application. To create a paste, use the
use stdin to provide the text: "--input" flag or provide the text on stdin:
$ cat list_of_ducks.txt | arc paste $ cat list_of_ducks.txt | arc paste
$ arc paste --input list_of_ducks.txt
To retrieve a paste, specify the paste ID: To retrieve a paste, specify the paste ID:
@ -34,8 +35,12 @@ EOTEXT
$this->newWorkflowArgument('lang') $this->newWorkflowArgument('lang')
->setParameter('language') ->setParameter('language')
->setHelp(pht('Language for the paste.')), ->setHelp(pht('Language for the paste.')),
$this->newWorkflowArgument('json') $this->newWorkflowArgument('input')
->setHelp(pht('Output in JSON format.')), ->setParameter('path')
->setIsPathArgument(true)
->setHelp(pht('Create a paste using the content in a file.')),
$this->newWorkflowArgument('browse')
->setHelp(pht('After creating a paste, open it in a web browser.')),
$this->newWorkflowArgument('argv') $this->newWorkflowArgument('argv')
->setWildcard(true), ->setWildcard(true),
); );
@ -44,6 +49,8 @@ EOTEXT
public function runWorkflow() { public function runWorkflow() {
$set_language = $this->getArgument('lang'); $set_language = $this->getArgument('lang');
$set_title = $this->getArgument('title'); $set_title = $this->getArgument('title');
$is_browse = $this->getArgument('browse');
$input_path = $this->getArgument('input');
$argv = $this->getArgument('argv'); $argv = $this->getArgument('argv');
if (count($argv) > 1) { if (count($argv) > 1) {
@ -52,6 +59,8 @@ EOTEXT
'Specify only one paste to retrieve.')); 'Specify only one paste to retrieve.'));
} }
$is_read = (count($argv) === 1);
$symbols = $this->getSymbolEngine(); $symbols = $this->getSymbolEngine();
if (count($argv) === 1) { if (count($argv) === 1) {
@ -67,6 +76,19 @@ EOTEXT
'Flag "--title" is not supported when reading pastes.')); 'Flag "--title" is not supported when reading pastes.'));
} }
if ($is_browse) {
throw new PhutilArgumentUsageException(
pht(
'Flag "--browse" is not supported when reading pastes. Use '.
'"arc browse" to browse known objects.'));
}
if ($input_path !== null) {
throw new PhutilArgumentUsageException(
pht(
'Flag "--input" is not supported when reading pastes.'));
}
$paste_symbol = $argv[0]; $paste_symbol = $argv[0];
$paste_ref = $symbols->loadPasteForSymbol($paste_symbol); $paste_ref = $symbols->loadPasteForSymbol($paste_symbol);
@ -74,7 +96,8 @@ EOTEXT
throw new PhutilArgumentUsageException( throw new PhutilArgumentUsageException(
pht( pht(
'Paste "%s" does not exist, or you do not have access '. 'Paste "%s" does not exist, or you do not have access '.
'to see it.')); 'to see it.',
$paste_symbol));
} }
echo $paste_ref->getContent(); echo $paste_ref->getContent();
@ -82,7 +105,11 @@ EOTEXT
return 0; return 0;
} }
if ($input_path === null || $input_path === '-') {
$content = $this->readStdin(); $content = $this->readStdin();
} else {
$content = Filesystem::readFile($input_path);
}
$xactions = array(); $xactions = array();
@ -121,6 +148,9 @@ EOTEXT
$paste_phid = idxv($result, array('object', 'phid')); $paste_phid = idxv($result, array('object', 'phid'));
$paste_ref = $symbols->loadPasteForSymbol($paste_phid); $paste_ref = $symbols->loadPasteForSymbol($paste_phid);
$uri = $paste_ref->getURI();
$uri = $this->getAbsoluteURI($uri);
$log = $this->getLogEngine(); $log = $this->getLogEngine();
$log->writeSuccess( $log->writeSuccess(
@ -130,7 +160,11 @@ EOTEXT
echo tsprintf( echo tsprintf(
'%s', '%s',
$paste_ref->newDisplayRef() $paste_ref->newDisplayRef()
->setURI($paste_ref->getURI())); ->setURI($uri));
if ($is_browse) {
$this->openURIsInBrowser(array($uri));
}
return 0; return 0;
} }