1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-22 11:39:03 +01:00

Add bin/files cat to print a file to stdout

Summary:
Ref T7149. This makes debugging some of this stuff a bit easier by removing the HTTP part in the middle.

Particularly, I anticipate having this stream data chunk-by-chunk in the near future.

Test Plan: Ran `files cat F23`, got output.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: joshuaspence, epriestley

Maniphest Tasks: T7149

Differential Revision: https://secure.phabricator.com/D12062
This commit is contained in:
epriestley 2015-03-13 11:30:13 -07:00
parent 4aed453b06
commit 6c3552f939
3 changed files with 60 additions and 16 deletions

View file

@ -1832,6 +1832,7 @@ phutil_register_library_map(array(
'PhabricatorFilesApplication' => 'applications/files/application/PhabricatorFilesApplication.php',
'PhabricatorFilesApplicationStorageEnginePanel' => 'applications/files/applicationpanel/PhabricatorFilesApplicationStorageEnginePanel.php',
'PhabricatorFilesConfigOptions' => 'applications/files/config/PhabricatorFilesConfigOptions.php',
'PhabricatorFilesManagementCatWorkflow' => 'applications/files/management/PhabricatorFilesManagementCatWorkflow.php',
'PhabricatorFilesManagementCompactWorkflow' => 'applications/files/management/PhabricatorFilesManagementCompactWorkflow.php',
'PhabricatorFilesManagementEnginesWorkflow' => 'applications/files/management/PhabricatorFilesManagementEnginesWorkflow.php',
'PhabricatorFilesManagementMigrateWorkflow' => 'applications/files/management/PhabricatorFilesManagementMigrateWorkflow.php',
@ -5138,6 +5139,7 @@ phutil_register_library_map(array(
'PhabricatorFilesApplication' => 'PhabricatorApplication',
'PhabricatorFilesApplicationStorageEnginePanel' => 'PhabricatorApplicationConfigurationPanel',
'PhabricatorFilesConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorFilesManagementCatWorkflow' => 'PhabricatorFilesManagementWorkflow',
'PhabricatorFilesManagementCompactWorkflow' => 'PhabricatorFilesManagementWorkflow',
'PhabricatorFilesManagementEnginesWorkflow' => 'PhabricatorFilesManagementWorkflow',
'PhabricatorFilesManagementMigrateWorkflow' => 'PhabricatorFilesManagementWorkflow',

View file

@ -0,0 +1,39 @@
<?php
final class PhabricatorFilesManagementCatWorkflow
extends PhabricatorFilesManagementWorkflow {
protected function didConstruct() {
$this
->setName('cat')
->setSynopsis(
pht('Print the contents of a file.'))
->setArguments(
array(
array(
'name' => 'names',
'wildcard' => true,
),
));
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$names = $args->getArg('names');
if (count($names) > 1) {
throw new PhutilArgumentUsageException(
pht('Specify exactly one file to print, like "F123".'));
} else if (!$names) {
throw new PhutilArgumentUsageException(
pht('Specify a file to print, like "F123".'));
}
$file = head($this->loadFilesWithNames($names));
echo $file->loadFileData();
return 0;
}
}

View file

@ -15,26 +15,29 @@ abstract class PhabricatorFilesManagementWorkflow
}
if ($names) {
$query = id(new PhabricatorObjectQuery())
->setViewer($this->getViewer())
->withNames($names)
->withTypes(array(PhabricatorFileFilePHIDType::TYPECONST));
$query->execute();
$files = $query->getNamedResults();
foreach ($names as $name) {
if (empty($files[$name])) {
throw new PhutilArgumentUsageException(
"No file '{$name}' exists!");
}
}
return array_values($files);
return $this->loadFilesWithNames($names);
}
return null;
}
protected function loadFilesWithNames(array $names) {
$query = id(new PhabricatorObjectQuery())
->setViewer($this->getViewer())
->withNames($names)
->withTypes(array(PhabricatorFileFilePHIDType::TYPECONST));
$query->execute();
$files = $query->getNamedResults();
foreach ($names as $name) {
if (empty($files[$name])) {
throw new PhutilArgumentUsageException(
"No file '{$name}' exists!");
}
}
return array_values($files);
}
}