@@ -19,12 +19,13 @@ if (!in_array($command, $commands, true)) {
1919 exit (1 );
2020}
2121
22- $ runCommand = function (string $ command ) {
22+ $ runCommand = function (string $ command ): int {
2323 echo $ command . "\n" ;
24- echo system ($ command );
24+ echo system ($ command , $ resultCode );
25+ return $ resultCode ;
2526};
2627
27- $ buildBook = function (string $ book ) use ($ runCommand ) {
28+ $ buildBook = function (string $ book ) use ($ runCommand ): int {
2829 $ command = <<<COMMAND
2930cd page; hugo \
3031 --cleanDestinationDir \
@@ -34,11 +35,11 @@ cd page; hugo \
3435 --baseURL https://extensions.terminal42.ch/docs/{book}/
3536COMMAND ;
3637
37- $ runCommand (str_replace ('{book} ' , $ book , $ command ));
38+ return $ runCommand (str_replace ('{book} ' , $ book , $ command ));
3839};
3940
4041
41- $ liveBook = function (string $ book ) use ($ runCommand ) {
42+ $ liveBook = function (string $ book ) use ($ runCommand ): int {
4243 $ command = <<<COMMAND
4344cd page; hugo server \
4445 --cleanDestinationDir \
@@ -47,24 +48,25 @@ cd page; hugo server \
4748 --logLevel info
4849COMMAND ;
4950
50- $ runCommand (str_replace ('{book} ' , $ book , $ command ));
51+ return $ runCommand (str_replace ('{book} ' , $ book , $ command ));
5152};
5253
5354preg_match ('/^(build|live)-(.*)/ ' , $ command , $ matches );
5455
5556if ('build-all ' === $ matches [0 ]) {
5657 foreach ($ books as $ book ) {
57- $ buildBook ($ book );
58+ $ result = $ buildBook ($ book );
59+ if (0 !== $ result ) {
60+ exit ($ result );
61+ }
5862 }
59- return ;
63+ exit ( 0 ) ;
6064}
6165
6266if ('build ' === $ matches [1 ]) {
63- $ buildBook ($ matches [2 ]);
64- return ;
67+ exit ($ buildBook ($ matches [2 ]));
6568}
6669
6770if ('live ' === $ matches [1 ]) {
68- $ liveBook ($ matches [2 ]);
69- return ;
71+ exit ($ liveBook ($ matches [2 ]));
7072}
0 commit comments