Page MenuHomePhabricator

D12062.id29039.diff
No OneTemporary

D12062.id29039.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1832,6 +1832,7 @@
'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 @@
'PhabricatorFilesApplication' => 'PhabricatorApplication',
'PhabricatorFilesApplicationStorageEnginePanel' => 'PhabricatorApplicationConfigurationPanel',
'PhabricatorFilesConfigOptions' => 'PhabricatorApplicationConfigOptions',
+ 'PhabricatorFilesManagementCatWorkflow' => 'PhabricatorFilesManagementWorkflow',
'PhabricatorFilesManagementCompactWorkflow' => 'PhabricatorFilesManagementWorkflow',
'PhabricatorFilesManagementEnginesWorkflow' => 'PhabricatorFilesManagementWorkflow',
'PhabricatorFilesManagementMigrateWorkflow' => 'PhabricatorFilesManagementWorkflow',
diff --git a/src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php b/src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/applications/files/management/PhabricatorFilesManagementCatWorkflow.php
@@ -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;
+ }
+
+}
diff --git a/src/applications/files/management/PhabricatorFilesManagementWorkflow.php b/src/applications/files/management/PhabricatorFilesManagementWorkflow.php
--- a/src/applications/files/management/PhabricatorFilesManagementWorkflow.php
+++ b/src/applications/files/management/PhabricatorFilesManagementWorkflow.php
@@ -15,26 +15,29 @@
}
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);
+ }
}

File Metadata

Mime Type
text/plain
Expires
Oct 15 2024, 11:05 AM (5 w, 18 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6712608
Default Alt Text
D12062.id29039.diff (4 KB)

Event Timeline