Skip to content

Commit

Permalink
Add cd (change directory) and within (run commands within a directory…
Browse files Browse the repository at this point in the history
… and revert to the previous working_path).
  • Loading branch information
tomzx committed Feb 14, 2015
1 parent 7a5e900 commit f5bc859
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ function after($it, $that)
$afterScenario->addAfter($scenario);
}

/**
* Change the current working directory.
*
* @param string $path
*/
function cd($path)
{
env('working_path', $path);
}

/**
* Execute a callback within a specific directory and revert back to the initial working directory.
*
* @param string $path
* @param callable $callback
*/
function within($path, $callback)
{
$lastWorkingPath = workingPath();
env()->set('working_path', $path);
$callback();
env()->set('working_path', $lastWorkingPath);
}

/**
* Return the current working path.
*
* @return string
*/
function workingPath()
{
return env()->get('working_path', env()->get(Environment::DEPLOY_PATH));
}

/**
* Run command on server.
*
Expand All @@ -149,7 +183,10 @@ function after($it, $that)
function run($command)
{
$server = Context::get()->getServer();
$command = Context::get()->getEnvironment()->parse($command);
$command = env()->parse($command);
$workingPath = workingPath();

$command = "cd $workingPath && $command";

if (isVeryVerbose()) {
writeln("<comment>Run</comment>: $command");
Expand Down

0 comments on commit f5bc859

Please sign in to comment.