This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to change the working directory
- Loading branch information
1 parent
407fc4c
commit 03a8091
Showing
6 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Elgentos\Masquerade; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class WorkingDirectory | ||
{ | ||
const OPTION_NAME = 'working-dir'; | ||
const DESCRIPTION = 'Set the working directory'; | ||
|
||
public static function change(InputInterface $input) | ||
{ | ||
$workingDir = $input->getOption(self::OPTION_NAME) ?? null; | ||
|
||
if (null === $workingDir) { | ||
return; | ||
} | ||
|
||
Assert::directory($workingDir, 'Could not change the working directory to %s: directory does not exists or file is not a directory.'); | ||
|
||
if (false === chdir($workingDir)) { | ||
throw new \RuntimeException( | ||
sprintf( | ||
'Failed to change the working directory to "%s" from "%s".', | ||
$workingDir, | ||
getcwd(), | ||
), | ||
); | ||
} | ||
} | ||
} |