33namespace Krak \PhpInc \Command ;
44
55use Krak \PhpInc ,
6- Symfony \Component \Console ;
6+ Symfony \Component \Console ,
7+ Webmozart \PathUtil \Path ;
78
89class 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}
0 commit comments