1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

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
This commit is contained in:
epriestley 2018-10-11 12:35:11 -07:00
parent 4f54d483d5
commit 8bffc9ea0e

View file

@ -77,14 +77,27 @@ final class PhabricatorBulkManagementExportWorkflow
$is_overwrite = $args->getArg('overwrite');
$output_path = $args->getArg('output');
if (!strlen($output_path) && $is_overwrite) {
if (!strlen($output_path)) {
throw new PhutilArgumentUsageException(
pht(
'Flag "--overwrite" has no effect without "--output".'));
'Use "--output <path>" to specify an output file, or "--output -" '.
'to print to stdout.'));
}
if ($output_path === '-') {
$is_stdout = true;
} else {
$is_stdout = false;
}
if ($is_stdout && $is_overwrite) {
throw new PhutilArgumentUsageException(
pht(
'Flag "--overwrite" has no effect when outputting to stdout.'));
}
if (!$is_overwrite) {
if (Filesystem::pathExists($output_path)) {
if (!$is_stdout && Filesystem::pathExists($output_path)) {
throw new PhutilArgumentUsageException(
pht(
'Output path already exists. Use "--overwrite" to overwrite '.
@ -113,7 +126,7 @@ final class PhabricatorBulkManagementExportWorkflow
$iterator = $file->getFileDataIterator();
if (strlen($output_path)) {
if (!$is_stdout) {
// Empty the file before we start writing to it. Otherwise, "--overwrite"
// will really mean "--append".
Filesystem::writeFile($output_path, '');
@ -121,6 +134,12 @@ final class PhabricatorBulkManagementExportWorkflow
foreach ($iterator as $chunk) {
Filesystem::appendFile($output_path, $chunk);
}
echo tsprintf(
"%s\n",
pht(
'Exported data to "%s".',
Filesystem::readablePath($output_path)));
} else {
foreach ($iterator as $chunk) {
echo $chunk;