Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15406648
D8021.id18165.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D8021.id18165.diff
View Options
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";
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 19, 1:07 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7685726
Default Alt Text
D8021.id18165.diff (2 KB)
Attached To
Mode
D8021: Make directory fixture script slightly more modern and usable
Attached
Detach File
Event Timeline
Log In to Comment