Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?php

use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
use Behat\Behat\Context\BehatContext;
use Behat\Gherkin\Node\PyStringNode;

/**
* Features context.
Expand All @@ -17,34 +13,34 @@ class FeatureContext extends BehatContext
*/
public function iHaveADirectory($directory)
{
if (!file_exists($directory)) {
mkdir($directory);
}
if (!file_exists($directory)) {
mkdir($directory);
}
}

/**
* @Given /^I [sh]ave a file named "([^"]*)" in "([^"]*)"$/
*/
public function iHaveAFileNamedIn($fileName, $directory)
{
touch($directory . DIRECTORY_SEPARATOR . $fileName);
touch($directory.DIRECTORY_SEPARATOR.$fileName);
}

/**
* @When /^I run "([^"]*)"$/
*/
public function iRun($command)
{
exec($command, $output);
$this->output = trim(implode("\n", $output));
exec($command, $output);
$this->output = trim(implode("\n", $output));
}

/** @Then /^I should get:$/ */
public function iShouldGet(PyStringNode $string)
{
if ((string) $string !== $this->output) {
throw new Exception(
"Actual output is:\n" . $this->output
"Actual output is:\n".$this->output
);
}
}
Expand Down
50 changes: 26 additions & 24 deletions src/Eher/PHPWatch/PHPWatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private function proccessOptions($options)
$this->writeln("");
exit(1);
} else {
$this->extension = "*." . $options['ext'];
$this->extension = "*.".$options['ext'];
}
}

Expand All @@ -55,38 +55,38 @@ private function proccessOptions($options)

private function showHelp()
{
$this->writeln("Usage: phpwatch [options] \"command\" path");
$this->writeln("");
$this->writeln(" --ext Filter files by extension");
$this->writeln(" --once Executes the command once");
$this->writeln(" --verbose Verbose mode");
$this->writeln(" --help Show this message");
$this->writeln(" --version Show the version");
$this->writeln("");
exit;
$this->writeln("Usage: phpwatch [options] \"command\" path");
$this->writeln("");
$this->writeln(" --ext Filter files by extension");
$this->writeln(" --once Executes the command once");
$this->writeln(" --verbose Verbose mode");
$this->writeln(" --help Show this message");
$this->writeln(" --version Show the version");
$this->writeln("");
exit;
}

private function showVersion()
{
$this->writeln("New Version!");
exit;
$this->writeln("New Version!");
exit;
}

private function watchFiles($command, $path)
{
$this->writeln("phpwatch: running...");
if ($this->verbose) {
$this->writeln("Watching => $path");
}
while(true) {
if ($this->hasChangesIn($path)) {
$this->runCommand($command);
if ($this->once) {
exit;
}
$this->writeln("phpwatch: running...");
if ($this->verbose) {
$this->writeln("Watching => $path");
}
while (true) {
if ($this->hasChangesIn($path)) {
$this->runCommand($command);
if ($this->once) {
exit;
}
sleep(1);
}
sleep(1);
}
}

private function hasChangesIn($path)
Expand All @@ -104,8 +104,10 @@ private function hasChangesIn($path)
if ($this->verbose) {
$this->writeln($file->getRelativePathname());
}

return true;
}

return false;
}

Expand All @@ -119,6 +121,6 @@ private function runCommand($command)

private function showDefaultMessage()
{
$this->writeln("Use 'phpwatch --help' for more info");
$this->writeln("Use 'phpwatch --help' for more info");
}
}