2929use OCP \IConfig ;
3030use OCP \Util ;
3131use Symfony \Component \Console \Input \InputInterface ;
32+ use Symfony \Component \Console \Input \InputOption ;
3233use Symfony \Component \Console \Output \OutputInterface ;
3334
3435class Status extends Base {
@@ -47,22 +48,40 @@ protected function configure() {
4748
4849 $ this
4950 ->setDescription ('show some status information ' )
50- ;
51+ ->addOption (
52+ 'exit-code ' ,
53+ 'e ' ,
54+ InputOption::VALUE_NONE ,
55+ 'exit with 0 if running in normal mode, 1 when in maintenance mode, 2 when `./occ upgrade` is needed. Does not write any output to STDOUT. '
56+ );
5157 }
5258
5359 protected function execute (InputInterface $ input , OutputInterface $ output ): int {
60+ $ maintenanceMode = $ this ->config ->getSystemValueBool ('maintenance ' , false );
61+ $ needUpgrade = Util::needUpgrade ();
5462 $ values = [
5563 'installed ' => $ this ->config ->getSystemValueBool ('installed ' , false ),
5664 'version ' => implode ('. ' , Util::getVersion ()),
5765 'versionstring ' => OC_Util::getVersionString (),
5866 'edition ' => '' ,
59- 'maintenance ' => $ this -> config -> getSystemValueBool ( ' maintenance ' , false ) ,
60- 'needsDbUpgrade ' => Util:: needUpgrade () ,
67+ 'maintenance ' => $ maintenanceMode ,
68+ 'needsDbUpgrade ' => $ needUpgrade ,
6169 'productname ' => $ this ->themingDefaults ->getProductName (),
6270 'extendedSupport ' => Util::hasExtendedSupport ()
6371 ];
6472
65- $ this ->writeArrayInOutputFormat ($ input , $ output , $ values );
73+ if ($ input ->getOption ('verbose ' ) || !$ input ->getOption ('exit-code ' )) {
74+ $ this ->writeArrayInOutputFormat ($ input , $ output , $ values );
75+ }
76+
77+ if ($ input ->getOption ('exit-code ' )) {
78+ if ($ maintenanceMode === true ) {
79+ return 1 ;
80+ }
81+ if ($ needUpgrade === true ) {
82+ return 2 ;
83+ }
84+ }
6685 return 0 ;
6786 }
6887}
0 commit comments