Index: scripts/utils/directory_fixture.php =================================================================== --- scripts/utils/directory_fixture.php +++ scripts/utils/directory_fixture.php @@ -18,7 +18,11 @@ $args->parse(array( array( 'name' => 'create', - 'help' => 'Create a new fixture.', + 'help' => pht('Create a new fixture.'), + ), + array( + 'name' => 'read-only', + 'help' => pht('Do not save changes made to the fixture.'), ), array( 'name' => 'files', @@ -27,35 +31,60 @@ )); $is_create = $args->getArg('create'); +$is_read_only = $args->getArg('read-only'); +$console = PhutilConsole::getConsole(); $files = $args->getArg('files'); if (count($files) !== 1) { - echo "Specify exactly one file to edit.\n"; - exit(1); + throw new PhutilArgumentUsageException( + pht('Specify exactly one file to create or edit.')); } $file = head($files); if ($is_create) { if (Filesystem::pathExists($file)) { - echo "File '{$file}' already exists!\n"; - exit(1); + throw new PhutilArgumentUsageException( + pht('File "%s" already exists, so you can not --create it.', $file)); } $fixture = PhutilDirectoryFixture::newEmptyFixture(); } else { if (!Filesystem::pathExists($file)) { - echo "File '{$file}' does not exist!\n"; - exit(1); + throw new PhutilArgumentUsageException( + pht( + 'File "%s" does not exist! Use --create to create a new fixture.', + $file)); } $fixture = PhutilDirectoryFixture::newFromArchive($file); } -echo "Spawning an interactive shell. Exit when complete.\n\n"; +$console->writeOut( + "%s\n\n", + pht('Spawning an interactive shell. Working directory is:')); +$console->writeOut( + " %s\n\n", + $fixture->getPath()); +if ($is_read_only) { + $console->writeOut( + "%s\n", + pht('Exit the shell when done (this fixture is read-only).')); +} else { + $console->writeOut( + "%s\n", + pht('Exit the shell after making changes.')); +} $err = phutil_passthru('cd %s && sh', $fixture->getPath()); if ($err) { + $console->writeOut( + "%s\n", + pht('Shell exited with error %d, discarding changes.', $err)); exit($err); +} else if ($is_read_only) { + $console->writeOut( + "%s\n", + pht('Invoked in read-only mode, discarding changes.')); +} else { + $console->writeOut("%s\n", pht('Updating archive...')); + $fixture->saveToArchive($file); + $console->writeOut("%s\n", pht('Done.')); } - -echo "Updating archive...\n"; -$fixture->saveToArchive($file); -echo "Done.\n";