Remove product literal strings in "pht()", part 5
[phabricator.git] / src / applications / files / management / PhabricatorFilesManagementCatWorkflow.php
blob5bf40a057d143650312dfc3490ad66688a0ae6c5
1 <?php
3 final class PhabricatorFilesManagementCatWorkflow
4 extends PhabricatorFilesManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('cat')
9 ->setSynopsis(pht('Print the contents of a file.'))
10 ->setArguments(
11 array(
12 array(
13 'name' => 'begin',
14 'param' => 'bytes',
15 'help' => pht('Begin printing at a specific offset.'),
17 array(
18 'name' => 'end',
19 'param' => 'bytes',
20 'help' => pht('End printing at a specific offset.'),
22 array(
23 'name' => 'salvage',
24 'help' => pht(
25 'DANGEROUS. Attempt to salvage file content even if the '.
26 'integrity check fails. If an adversary has tampered with '.
27 'the file, the content may be unsafe.'),
29 array(
30 'name' => 'names',
31 'wildcard' => true,
33 ));
36 public function execute(PhutilArgumentParser $args) {
37 $console = PhutilConsole::getConsole();
39 $names = $args->getArg('names');
40 if (count($names) > 1) {
41 throw new PhutilArgumentUsageException(
42 pht('Specify exactly one file to print, like "%s".', 'F123'));
43 } else if (!$names) {
44 throw new PhutilArgumentUsageException(
45 pht('Specify a file to print, like "%s".', 'F123'));
48 $file = head($this->loadFilesWithNames($names));
50 $begin = $args->getArg('begin');
51 $end = $args->getArg('end');
53 $file->makeEphemeral();
55 // If we're running in "salvage" mode, wipe out any integrity hash which
56 // may be present. This makes us read file data without performing an
57 // integrity check.
58 $salvage = $args->getArg('salvage');
59 if ($salvage) {
60 $file->setIntegrityHash(null);
63 try {
64 $iterator = $file->getFileDataIterator($begin, $end);
65 foreach ($iterator as $data) {
66 echo $data;
68 } catch (PhabricatorFileIntegrityException $ex) {
69 throw new PhutilArgumentUsageException(
70 pht(
71 'File data integrity check failed. Use "--salvage" to bypass '.
72 'integrity checks. This flag is dangerous, use it at your own '.
73 'risk. Underlying error: %s',
74 $ex->getMessage()));
77 return 0;