1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-26 00:32:41 +01:00

Add "--browse" to "arc upload" and update behavior, particularly "--json"

Summary:
Ref T13528. Provide a "--browse" flag to open files after they are uploaded.

Update the code to use modern query strategies.

This impacts the output of "--json", which was just raw "file.info" output before and could not represent the same path being passed several times (`arc upload X X`).

Test Plan: Ran `arc upload` with `--browse` and `--json`.

Maniphest Tasks: T13528

Differential Revision: https://secure.phabricator.com/D21202
This commit is contained in:
epriestley 2020-05-01 07:44:57 -07:00
parent 5448fe2165
commit c0d151e0e9
4 changed files with 86 additions and 32 deletions

View file

@ -234,21 +234,8 @@ EOTEXT
$ref_uri = head($ref_uris); $ref_uri = head($ref_uris);
// TODO: "ArcanistRevisionRef", at least, may return a relative URI.
// If we get a relative URI, guess the correct absolute URI based on
// the Conduit URI. This might not be correct for Conduit over SSH.
$raw_uri = $ref_uri->getURI(); $raw_uri = $ref_uri->getURI();
$raw_uri = $this->getAbsoluteURI($raw_uri);
$raw_uri = new PhutilURI($raw_uri);
if (!strlen($raw_uri->getDomain())) {
$base_uri = $this->getConduitEngine()
->getConduitURI();
$raw_uri = id(new PhutilURI($base_uri))
->setPath($raw_uri->getPath());
}
$raw_uri = phutil_string_cast($raw_uri);
$uris[] = $raw_uri; $uris[] = $raw_uri;
} }

View file

@ -37,6 +37,16 @@ final class ArcanistFileRef
return idxv($this->parameters, array('fields', 'size')); return idxv($this->parameters, array('fields', 'size'));
} }
public function getURI() {
$uri = idxv($this->parameters, array('fields', 'uri'));
if ($uri === null) {
$uri = '/'.$this->getMonogram();
}
return $uri;
}
public function getMonogram() { public function getMonogram() {
return 'F'.$this->getID(); return 'F'.$this->getID();
} }

View file

@ -23,6 +23,10 @@ EOTEXT
return array( return array(
$this->newWorkflowArgument('json') $this->newWorkflowArgument('json')
->setHelp(pht('Output upload information in JSON format.')), ->setHelp(pht('Output upload information in JSON format.')),
$this->newWorkflowArgument('browse')
->setHelp(
pht(
'After the upload completes, open the files in a web browser.')),
$this->newWorkflowArgument('temporary') $this->newWorkflowArgument('temporary')
->setHelp( ->setHelp(
pht( pht(
@ -42,6 +46,7 @@ EOTEXT
$is_temporary = $this->getArgument('temporary'); $is_temporary = $this->getArgument('temporary');
$is_json = $this->getArgument('json'); $is_json = $this->getArgument('json');
$is_browse = $this->getArgument('browse');
$paths = $this->getArgument('paths'); $paths = $this->getArgument('paths');
$conduit = $this->getConduitEngine(); $conduit = $this->getConduitEngine();
@ -65,35 +70,68 @@ EOTEXT
$files = $uploader->uploadFiles(); $files = $uploader->uploadFiles();
$results = array(); $phids = array();
foreach ($files as $file) { foreach ($files as $file) {
// TODO: This could be handled more gracefully; just preserving behavior // TODO: This could be handled more gracefully.
// until we introduce `file.query` and modernize this.
if ($file->getErrors()) { if ($file->getErrors()) {
throw new Exception(implode("\n", $file->getErrors())); throw new Exception(implode("\n", $file->getErrors()));
} }
$phid = $file->getPHID(); $phids[] = $file->getPHID();
$name = $file->getName(); }
$info = $conduit->resolveCall( $symbols = $this->getSymbolEngine();
'file.info', $symbol_refs = $symbols->loadFilesForSymbols($phids);
array(
'phid' => $phid,
));
$results[$path] = $info; $refs = array();
foreach ($symbol_refs as $symbol_ref) {
if (!$is_json) { $ref = $symbol_ref->getObject();
$id = $info['id']; if ($ref === null) {
echo " F{$id} {$name}: ".$info['uri']."\n\n"; throw new Exception(
pht(
'Failed to resolve symbol ref "%s".',
$symbol_ref->getSymbol()));
} }
$refs[] = $ref;
} }
if ($is_json) { if ($is_json) {
$output = id(new PhutilJSON())->encodeFormatted($results); $json = array();
echo $output;
foreach ($refs as $key => $ref) {
$uri = $ref->getURI();
$uri = $this->getAbsoluteURI($uri);
$map = array(
'argument' => $paths[$key],
'id' => $ref->getID(),
'phid' => $ref->getPHID(),
'name' => $ref->getName(),
'uri' => $uri,
);
$json[] = $map;
}
echo id(new PhutilJSON())->encodeAsList($json);
} else { } else {
$this->writeStatus(pht('Done.')); foreach ($refs as $ref) {
$uri = $ref->getURI();
$uri = $this->getAbsoluteURI($uri);
echo tsprintf(
'%s',
$ref->newDisplayRef()
->setURI($uri));
}
}
if ($is_browse) {
$uris = array();
foreach ($refs as $ref) {
$uri = $ref->getURI();
$uri = $this->getAbsoluteURI($uri);
$uris[] = $uri;
}
$this->openURIsInBrowser($uris);
} }
return 0; return 0;

View file

@ -2421,4 +2421,23 @@ abstract class ArcanistWorkflow extends Phobject {
return $stdin->read(); return $stdin->read();
} }
protected function getAbsoluteURI($raw_uri) {
// TODO: "ArcanistRevisionRef", at least, may return a relative URI.
// If we get a relative URI, guess the correct absolute URI based on
// the Conduit URI. This might not be correct for Conduit over SSH.
$raw_uri = new PhutilURI($raw_uri);
if (!strlen($raw_uri->getDomain())) {
$base_uri = $this->getConduitEngine()
->getConduitURI();
$raw_uri = id(new PhutilURI($base_uri))
->setPath($raw_uri->getPath());
}
$raw_uri = phutil_string_cast($raw_uri);
return $raw_uri;
}
} }