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:
parent
c0d151e0e9
commit
af9faba02f
2 changed files with 48 additions and 8 deletions
|
@ -30,7 +30,13 @@ final class ArcanistPasteRef
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -9,10 +9,11 @@ final class ArcanistPasteWorkflow
|
|||
|
||||
public function getWorkflowInformation() {
|
||||
$help = pht(<<<EOTEXT
|
||||
Share and grab text using the Paste application. To create a paste,
|
||||
use stdin to provide the text:
|
||||
Share and grab text using the Paste application. To create a paste, use the
|
||||
"--input" flag or provide the text on stdin:
|
||||
|
||||
$ cat list_of_ducks.txt | arc paste
|
||||
$ arc paste --input list_of_ducks.txt
|
||||
|
||||
To retrieve a paste, specify the paste ID:
|
||||
|
||||
|
@ -34,8 +35,12 @@ EOTEXT
|
|||
$this->newWorkflowArgument('lang')
|
||||
->setParameter('language')
|
||||
->setHelp(pht('Language for the paste.')),
|
||||
$this->newWorkflowArgument('json')
|
||||
->setHelp(pht('Output in JSON format.')),
|
||||
$this->newWorkflowArgument('input')
|
||||
->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')
|
||||
->setWildcard(true),
|
||||
);
|
||||
|
@ -44,6 +49,8 @@ EOTEXT
|
|||
public function runWorkflow() {
|
||||
$set_language = $this->getArgument('lang');
|
||||
$set_title = $this->getArgument('title');
|
||||
$is_browse = $this->getArgument('browse');
|
||||
$input_path = $this->getArgument('input');
|
||||
|
||||
$argv = $this->getArgument('argv');
|
||||
if (count($argv) > 1) {
|
||||
|
@ -52,6 +59,8 @@ EOTEXT
|
|||
'Specify only one paste to retrieve.'));
|
||||
}
|
||||
|
||||
$is_read = (count($argv) === 1);
|
||||
|
||||
$symbols = $this->getSymbolEngine();
|
||||
|
||||
if (count($argv) === 1) {
|
||||
|
@ -67,6 +76,19 @@ EOTEXT
|
|||
'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_ref = $symbols->loadPasteForSymbol($paste_symbol);
|
||||
|
@ -74,7 +96,8 @@ EOTEXT
|
|||
throw new PhutilArgumentUsageException(
|
||||
pht(
|
||||
'Paste "%s" does not exist, or you do not have access '.
|
||||
'to see it.'));
|
||||
'to see it.',
|
||||
$paste_symbol));
|
||||
}
|
||||
|
||||
echo $paste_ref->getContent();
|
||||
|
@ -82,7 +105,11 @@ EOTEXT
|
|||
return 0;
|
||||
}
|
||||
|
||||
$content = $this->readStdin();
|
||||
if ($input_path === null || $input_path === '-') {
|
||||
$content = $this->readStdin();
|
||||
} else {
|
||||
$content = Filesystem::readFile($input_path);
|
||||
}
|
||||
|
||||
$xactions = array();
|
||||
|
||||
|
@ -121,6 +148,9 @@ EOTEXT
|
|||
$paste_phid = idxv($result, array('object', 'phid'));
|
||||
$paste_ref = $symbols->loadPasteForSymbol($paste_phid);
|
||||
|
||||
$uri = $paste_ref->getURI();
|
||||
$uri = $this->getAbsoluteURI($uri);
|
||||
|
||||
$log = $this->getLogEngine();
|
||||
|
||||
$log->writeSuccess(
|
||||
|
@ -130,7 +160,11 @@ EOTEXT
|
|||
echo tsprintf(
|
||||
'%s',
|
||||
$paste_ref->newDisplayRef()
|
||||
->setURI($paste_ref->getURI()));
|
||||
->setURI($uri));
|
||||
|
||||
if ($is_browse) {
|
||||
$this->openURIsInBrowser(array($uri));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue