99
1010namespace OCA \AppAPI \Command \Daemon ;
1111
12+ use OC \Core \Command \Base ;
1213use OCA \AppAPI \AppInfo \Application ;
1314use OCA \AppAPI \Service \DaemonConfigService ;
14-
1515use OCP \IAppConfig ;
16- use Symfony \Component \Console \Command \Command ;
1716use Symfony \Component \Console \Helper \Table ;
1817use Symfony \Component \Console \Input \InputInterface ;
19- use Symfony \Component \Console \Input \InputOption ;
2018use Symfony \Component \Console \Output \OutputInterface ;
2119
22- class ListDaemons extends Command {
20+ class ListDaemons extends Base {
2321
2422 public function __construct (
2523 private readonly DaemonConfigService $ daemonConfigService ,
@@ -29,9 +27,9 @@ public function __construct(
2927 }
3028
3129 protected function configure (): void {
30+ parent ::configure ();
3231 $ this ->setName ('app_api:daemon:list ' );
3332 $ this ->setDescription ('List registered daemons ' );
34- $ this ->addOption ('output ' , 'o ' , InputOption::VALUE_REQUIRED , 'Output format (json, table) ' , 'table ' );
3533 }
3634
3735 protected function execute (InputInterface $ input , OutputInterface $ output ): int {
@@ -43,15 +41,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4341
4442 $ defaultDaemonName = $ this ->appConfig ->getValueString (Application::APP_ID , 'default_daemon_config ' , lazy: true );
4543
46- $ outputFormat = $ input ->getOption ('output ' );
47- if (!in_array ($ outputFormat , ['json ' , 'table ' ], true )) {
48- $ output ->writeln (sprintf ('<error>Invalid output format "%s". Valid options are: json, table</error> ' , $ outputFormat ));
49- return 1 ;
50- }
51-
52- $ output ->writeln ('Registered ExApp daemon configs: ' );
53-
54- if ($ outputFormat === 'json ' ) {
44+ if (in_array ($ input ->getOption ('output ' ), [self ::OUTPUT_FORMAT_JSON , self ::OUTPUT_FORMAT_JSON_PRETTY ], true )) {
5545 $ allDaemonInfo = [];
5646 foreach ($ daemonConfigs as $ daemon ) {
5747 $ deployConfig = $ daemon ->getDeployConfig ();
@@ -68,9 +58,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6858 'host ' => $ daemon ->getHost (),
6959 'deploy_config ' => $ deployConfig ,
7060 ];
71-
7261 }
73- $ output -> writeln ( json_encode ( $ allDaemonInfo , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
62+ $ this -> writeArrayInOutputFormat ( $ input , $ output , $ allDaemonInfo );
7463 } else {
7564 $ table = new Table ($ output );
7665 $ headers = ['Def ' , 'Name ' , 'Display name ' , 'Deploy ID ' , 'Protocol ' , 'Host ' , 'NC Url ' , 'Is HaRP ' , 'HaRP FRP Address ' , 'HaRP Docker Socket Port ' ];
@@ -94,6 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9483 }
9584
9685 $ table ->setRows ($ rows );
86+ $ output ->writeln ('Registered ExApp daemon configs: ' );
9787 $ table ->render ();
9888 }
9989
0 commit comments