Skip to content

Commit de16ccb

Browse files
committed
Adding output option
Signed-off-by: RJ Garcia <[email protected]>
1 parent 91a1661 commit de16ccb

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
},
1818
"require": {
1919
"nikic/iter": "^1.4",
20-
"symfony/console": "^3.0"
20+
"symfony/console": "^3.0",
21+
"webmozart/path-util": "^2.3"
2122
},
2223
"bin": ["bin/php-inc"]
2324
}

src/Command/GenerateCommand.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Krak\PhpInc\Command;
44

55
use Krak\PhpInc,
6-
Symfony\Component\Console;
6+
Symfony\Component\Console,
7+
Webmozart\PathUtil\Path;
78

89
class GenerateCommand extends Console\Command\Command
910
{
@@ -14,18 +15,34 @@ protected function configure() {
1415
'path',
1516
Console\Input\InputArgument::REQUIRED,
1617
'The path of the source files to scan for'
18+
)
19+
->addOption(
20+
'output',
21+
'o',
22+
Console\Input\InputOption::VALUE_REQUIRED,
23+
'The output file to write too. This file will be exluded in inc matching'
1724
);
1825
}
1926

2027
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) {
21-
$match = PhpInc\andMatch([
28+
$o = $input->getOption('output');
29+
$o = $o ? Path::makeAbsolute($o, getcwd()) : null;
30+
$match = PhpInc\andMatch(array_filter([
2231
PhpInc\extMatch(['php']),
2332
PhpInc\lowerCaseMatch(),
2433
PhpInc\excludePathMatch('/.*\/Resources\/.*/'),
25-
]);
34+
$o ? PhpInc\excludePathMatch("@^$o$@") : null
35+
]));
36+
2637
$scan = PhpInc\scanSrc($match);
2738
$gen = PhpInc\genIncFile();
2839
$phpinc = PhpInc\phpInc($scan, $gen);
29-
$output->write($phpinc($input->getArgument('path')));
40+
$inc_file = $phpinc($input->getArgument('path'));
41+
42+
if ($o) {
43+
file_put_contents($o, $inc_file);
44+
} else {
45+
$output->write($inc_file);
46+
}
3047
}
3148
}

src/inc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
require_once __DIR__ . '/php-inc.php';

0 commit comments

Comments
 (0)