mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-02-18 01:38:38 +01:00
Provide "arc upload --json"
Summary: - Provide a "--json" flag for "arc upload" - Unify some of the stderr stuff across upload/download/paste. Test Plan: - Ran "arc upload" and "arc upload --json", piped stderr away with 2>/dev/null to verify only JSON got emitted to stdout - Ran "arc paste" Reviewed By: codeblock Reviewers: codeblock, jungejason, tuomaspelkonen, aran CC: aran, codeblock Differential Revision: 749
This commit is contained in:
parent
0e4f7774fb
commit
57ff80e6c4
4 changed files with 41 additions and 15 deletions
|
@ -919,4 +919,15 @@ class ArcanistBaseWorkflow {
|
||||||
return $user_config;
|
return $user_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a message to stderr so that '--json' flags or stdout which is meant
|
||||||
|
* to be piped somewhere aren't disrupted.
|
||||||
|
*
|
||||||
|
* @param string Message to write to stderr.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function writeStatusMessage($msg) {
|
||||||
|
file_put_contents('php://stderr', $msg);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ EOTEXT
|
||||||
|
|
||||||
$conduit = $this->getConduit();
|
$conduit = $this->getConduit();
|
||||||
|
|
||||||
$this->writeStatus("Getting file information...\n");
|
$this->writeStatusMessage("Getting file information...\n");
|
||||||
$info = $conduit->callMethodSynchronous(
|
$info = $conduit->callMethodSynchronous(
|
||||||
'file.info',
|
'file.info',
|
||||||
array(
|
array(
|
||||||
|
@ -96,7 +96,7 @@ EOTEXT
|
||||||
$desc = "'".$info['name']."' ".$desc;
|
$desc = "'".$info['name']."' ".$desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->writeStatus("Downloading file {$desc}...\n");
|
$this->writeStatusMessage("Downloading file {$desc}...\n");
|
||||||
$data = $conduit->callMethodSynchronous(
|
$data = $conduit->callMethodSynchronous(
|
||||||
'file.download',
|
'file.download',
|
||||||
array(
|
array(
|
||||||
|
@ -111,16 +111,10 @@ EOTEXT
|
||||||
$path = Filesystem::writeUniqueFile(
|
$path = Filesystem::writeUniqueFile(
|
||||||
nonempty($this->saveAs, $info['name'], 'file'),
|
nonempty($this->saveAs, $info['name'], 'file'),
|
||||||
$data);
|
$data);
|
||||||
$this->writeStatus("Saved file as '{$path}'.\n");
|
$this->writeStatusMessage("Saved file as '{$path}'.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function writeStatus($msg) {
|
|
||||||
// Use stderr instead of stdout since we may echo file contents to
|
|
||||||
// stdout with --show.
|
|
||||||
file_put_contents('php://stderr', $msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ EOTEXT
|
||||||
$conduit = $this->getConduit();
|
$conduit = $this->getConduit();
|
||||||
|
|
||||||
// Avoid confusion when people type "arc paste" with nothing else.
|
// Avoid confusion when people type "arc paste" with nothing else.
|
||||||
file_put_contents('php://stderr', "Reading paste from stdin...\n");
|
$this->writeStatusMessage("Reading paste from stdin...\n");
|
||||||
|
|
||||||
$info = $conduit->callMethodSynchronous(
|
$info = $conduit->callMethodSynchronous(
|
||||||
'paste.create',
|
'paste.create',
|
||||||
|
|
|
@ -24,10 +24,11 @@
|
||||||
final class ArcanistUploadWorkflow extends ArcanistBaseWorkflow {
|
final class ArcanistUploadWorkflow extends ArcanistBaseWorkflow {
|
||||||
|
|
||||||
private $paths;
|
private $paths;
|
||||||
|
private $json;
|
||||||
|
|
||||||
public function getCommandHelp() {
|
public function getCommandHelp() {
|
||||||
return phutil_console_format(<<<EOTEXT
|
return phutil_console_format(<<<EOTEXT
|
||||||
**upload** __file__ [__file__]
|
**upload** __file__ [__file__ ...] [--json]
|
||||||
Supports: filesystems
|
Supports: filesystems
|
||||||
Upload a file from local disk.
|
Upload a file from local disk.
|
||||||
|
|
||||||
|
@ -37,6 +38,9 @@ EOTEXT
|
||||||
|
|
||||||
public function getArguments() {
|
public function getArguments() {
|
||||||
return array(
|
return array(
|
||||||
|
'json' => array(
|
||||||
|
'help' => 'Output upload information in JSON format.',
|
||||||
|
),
|
||||||
'*' => 'paths',
|
'*' => 'paths',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -47,6 +51,7 @@ EOTEXT
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->paths = $this->getArgument('paths');
|
$this->paths = $this->getArgument('paths');
|
||||||
|
$this->json = $this->getArgument('json');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requiresAuthentication() {
|
public function requiresAuthentication() {
|
||||||
|
@ -57,17 +62,25 @@ EOTEXT
|
||||||
return $this->paths;
|
return $this->paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getJSON() {
|
||||||
|
return $this->json;
|
||||||
|
}
|
||||||
|
|
||||||
public function run() {
|
public function run() {
|
||||||
|
|
||||||
$conduit = $this->getConduit();
|
$conduit = $this->getConduit();
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
|
||||||
foreach ($this->paths as $path) {
|
foreach ($this->paths as $path) {
|
||||||
$name = basename($path);
|
$name = basename($path);
|
||||||
echo "Uploading '{$name}'...\n";
|
$this->writeStatusMessage("Uploading '{$name}'...\n");
|
||||||
try {
|
try {
|
||||||
$data = Filesystem::readFile($path);
|
$data = Filesystem::readFile($path);
|
||||||
} catch (FilesystemException $ex) {
|
} catch (FilesystemException $ex) {
|
||||||
echo "Unable to upload file: ".$ex->getMessage()."\n";
|
$this->writeStatusMessage(
|
||||||
|
"Unable to upload file: ".$ex->getMessage()."\n");
|
||||||
|
$results[$path] = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,10 +96,18 @@ EOTEXT
|
||||||
'phid' => $phid,
|
'phid' => $phid,
|
||||||
));
|
));
|
||||||
|
|
||||||
echo " {$name}: ".$info['uri']."\n\n";
|
$results[$path] = $info;
|
||||||
|
|
||||||
|
if (!$this->getJSON()) {
|
||||||
|
echo " {$name}: ".$info['uri']."\n\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Done.\n";
|
if ($this->getJSON()) {
|
||||||
|
echo json_encode($results)."\n";
|
||||||
|
} else {
|
||||||
|
$this->writeStatusMessage("Done.\n");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue