Skip to content

Commit

Permalink
Adding output option
Browse files Browse the repository at this point in the history
Signed-off-by: RJ Garcia <[email protected]>
  • Loading branch information
ragboyjr committed Mar 2, 2017
1 parent 91a1661 commit de16ccb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"require": {
"nikic/iter": "^1.4",
"symfony/console": "^3.0"
"symfony/console": "^3.0",
"webmozart/path-util": "^2.3"
},
"bin": ["bin/php-inc"]
}
25 changes: 21 additions & 4 deletions src/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Krak\PhpInc\Command;

use Krak\PhpInc,
Symfony\Component\Console;
Symfony\Component\Console,
Webmozart\PathUtil\Path;

class GenerateCommand extends Console\Command\Command
{
Expand All @@ -14,18 +15,34 @@ protected function configure() {
'path',
Console\Input\InputArgument::REQUIRED,
'The path of the source files to scan for'
)
->addOption(
'output',
'o',
Console\Input\InputOption::VALUE_REQUIRED,
'The output file to write too. This file will be exluded in inc matching'
);
}

protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) {
$match = PhpInc\andMatch([
$o = $input->getOption('output');
$o = $o ? Path::makeAbsolute($o, getcwd()) : null;
$match = PhpInc\andMatch(array_filter([
PhpInc\extMatch(['php']),
PhpInc\lowerCaseMatch(),
PhpInc\excludePathMatch('/.*\/Resources\/.*/'),
]);
$o ? PhpInc\excludePathMatch("@^$o$@") : null
]));

$scan = PhpInc\scanSrc($match);
$gen = PhpInc\genIncFile();
$phpinc = PhpInc\phpInc($scan, $gen);
$output->write($phpinc($input->getArgument('path')));
$inc_file = $phpinc($input->getArgument('path'));

if ($o) {
file_put_contents($o, $inc_file);
} else {
$output->write($inc_file);
}
}
}
3 changes: 3 additions & 0 deletions src/inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require_once __DIR__ . '/php-inc.php';

0 comments on commit de16ccb

Please sign in to comment.