@@ -24,9 +24,11 @@ class App
2424 public function __construct (Cli $ cli , Calculator $ calculator , ComposerFile $ composer , $ output )
2525 {
2626 $ this ->cli = $ cli ->description ('libyear: a simple measure of dependency freshness -- calculates the total number of years behind their respective newest versions for all dependencies listed in a composer.json file. ' )
27- ->opt ('quiet:q ' , 'only display outdated dependencies ' , false , 'boolean ' )
28- ->opt ('update:u ' , 'update composer.json with newest versions ' , false , 'boolean ' )
29- ->opt ('verbose:v ' , 'display network debug information ' , false , 'boolean ' )
27+ ->opt ('quiet:q ' , 'only display outdated dependencies ' )
28+ ->opt ('update:u ' , 'update composer.json with newest versions ' )
29+ ->opt ('verbose:v ' , 'display network debug information ' )
30+ ->opt ('limit:l ' , 'fails if total libyears behind is greater than this value ' )
31+ ->opt ('limit-any:a ' , 'fails if any dependency is more libyears behind than this value ' )
3032 ->arg ('path ' , 'the directory containing composer.json and composer.lock files ' );
3133 $ this ->calculator = $ calculator ;
3234 $ this ->composer = $ composer ;
@@ -53,6 +55,8 @@ public function run(array $args): bool
5355 $ quiet_mode = $ arguments ->getOpt ('quiet ' ) !== null ;
5456 $ update_mode = $ arguments ->getOpt ('update ' ) !== null ;
5557 $ verbose_mode = $ arguments ->getOpt ('verbose ' ) !== null ;
58+ $ limit_total = $ arguments ->getOpt ('limit ' );
59+ $ limit_any = $ arguments ->getOpt ('limit-any ' );
5660 $ dir = $ arguments ->getArg ('path ' ) ?? '. ' ;
5761
5862 $ real_dir = realpath ($ dir );
@@ -68,6 +72,23 @@ public function run(array $args): bool
6872
6973 fwrite ($ this ->output , "Total: $ total_display libyears behind \n" );
7074
75+ if ($ limit_any != null ) {
76+ $ beyond_limit = array_filter ($ dependencies , fn ($ d ) => $ d ->getLibyearsBehind () > $ limit_any );
77+
78+ /** @var Dependency $dependency */
79+ foreach ($ beyond_limit as $ dependency ) {
80+ $ behind = number_format ($ dependency ->getLibyearsBehind (), 2 );
81+ fwrite ($ this ->output , "{$ dependency ->name } is {$ behind } libyears behind, which is greater than the set limit of {$ limit_any }\n" );
82+ }
83+
84+ return sizeof ($ beyond_limit ) == 0 ;
85+ }
86+
87+ if ($ limit_total != null && $ total > $ limit_total ) {
88+ fwrite ($ this ->output , "Total libyears behind is greater than the set limit of {$ limit_total }\n" );
89+ return false ;
90+ }
91+
7192 if ($ update_mode ) {
7293 $ this ->composer ->update ($ dir , $ dependencies );
7394 fwrite ($ this ->output , "composer.json updated \n" );
0 commit comments