@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

In "bin/bulk export", require "--output <path>" by default

Summary:
Depends on D19743. Ref T13210. Since this command can easily dump a bunch of binary data (or just a huge long blob of nonsense) to stdout, default to requiring "--output <file>".

Using `--output -` will print to stdout.

Test Plan: Ran with: no `--output`, `--output file`, `--output -`, `--output - --overwrite`. Got sensible results or errors in all cases.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13210

Differential Revision: https://secure.phabricator.com/D19744

+23 -4
+23 -4
src/applications/transactions/bulk/management/PhabricatorBulkManagementExportWorkflow.php
··· 77 77 $is_overwrite = $args->getArg('overwrite'); 78 78 $output_path = $args->getArg('output'); 79 79 80 - if (!strlen($output_path) && $is_overwrite) { 80 + if (!strlen($output_path)) { 81 + throw new PhutilArgumentUsageException( 82 + pht( 83 + 'Use "--output <path>" to specify an output file, or "--output -" '. 84 + 'to print to stdout.')); 85 + } 86 + 87 + if ($output_path === '-') { 88 + $is_stdout = true; 89 + } else { 90 + $is_stdout = false; 91 + } 92 + 93 + if ($is_stdout && $is_overwrite) { 81 94 throw new PhutilArgumentUsageException( 82 95 pht( 83 - 'Flag "--overwrite" has no effect without "--output".')); 96 + 'Flag "--overwrite" has no effect when outputting to stdout.')); 84 97 } 85 98 86 99 if (!$is_overwrite) { 87 - if (Filesystem::pathExists($output_path)) { 100 + if (!$is_stdout && Filesystem::pathExists($output_path)) { 88 101 throw new PhutilArgumentUsageException( 89 102 pht( 90 103 'Output path already exists. Use "--overwrite" to overwrite '. ··· 113 126 114 127 $iterator = $file->getFileDataIterator(); 115 128 116 - if (strlen($output_path)) { 129 + if (!$is_stdout) { 117 130 // Empty the file before we start writing to it. Otherwise, "--overwrite" 118 131 // will really mean "--append". 119 132 Filesystem::writeFile($output_path, ''); ··· 121 134 foreach ($iterator as $chunk) { 122 135 Filesystem::appendFile($output_path, $chunk); 123 136 } 137 + 138 + echo tsprintf( 139 + "%s\n", 140 + pht( 141 + 'Exported data to "%s".', 142 + Filesystem::readablePath($output_path))); 124 143 } else { 125 144 foreach ($iterator as $chunk) { 126 145 echo $chunk;