diff --git a/src/ref/paste/ArcanistPasteRef.php b/src/ref/paste/ArcanistPasteRef.php index 04c8630d..2c4bb58d 100644 --- a/src/ref/paste/ArcanistPasteRef.php +++ b/src/ref/paste/ArcanistPasteRef.php @@ -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() { diff --git a/src/workflow/ArcanistPasteWorkflow.php b/src/workflow/ArcanistPasteWorkflow.php index 42df05b2..24468e7a 100644 --- a/src/workflow/ArcanistPasteWorkflow.php +++ b/src/workflow/ArcanistPasteWorkflow.php @@ -9,10 +9,11 @@ final class ArcanistPasteWorkflow public function getWorkflowInformation() { $help = pht(<<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; }